The following example is a short source code example of using the ApplicationLogger.
Declaration part
VAR
udiState : UDINT;
xSomethingHappened : BOOL;
fbLoggerPoint : APL.FB_LoggerPoint;
etDiagBuffer : GD.ET_Diag;
etDiagExtAplBuffer : APL.ET_DiagExt;
END_VAR
Program part
CASE udiState OF
0: // Machine initialization
// Register ApplicationLogger service
APL.G_ifApplicationLogger.RegisterCommunicationService();
// Register first LoggerPoint
fbLoggerPoint.RegisterLoggerPoint(
_ifParent := APL.G_ifApplicationLogger,
i_sName:= 'AplTest',
i_sType:= 'MyProject',
i_sSource := 'Project',
q_etDiag => etDiagBuffer,
q_etDiagExt => etDiagExtAplBuffer);
IF (etDiagBuffer = GD.ET_Diag.Ok) THEN
udiState := 10;
ELSE
// not able to register logger point -> check exception message of RegisterLoggerPoint
udiState := 100;
END_IF
10: // cyclic program
IF xSomethingHappened THEN
xSomethingHappened := FALSE;
// write message wia LoggerPoint
fbLoggerPoint.AddLogEntry(
i_etLogLevel := APL.ET_LogLevel.Exception,
i_etDiag := GD.ET_Diag.Ok,
i_udiDiagExt := 0,
i_sMessage := 'Something has happened!',
q_etDiag => etDiagBuffer,
q_etDiagExt => etDiagExtAplBuffer);
IF (etDiagBuffer <> GD.ET_Diag.Ok) THEN
// there was an exception during logging -> check exception message of AddLogEntry
udiState := 100;
END_IF
END_IF
END_CASE
By running this code on a controller and setting xSomethingHappened = TRUE, there is no message entry in the application logger by default. This is because the internal LogLevel of the LoggerPoints is set to Nothing per default. The LoggerPoint only logs messages which are of interest at the moment. This means that the input i_etLogLevel of the Method fbLoggerPoint.AddLogEntry is set to an equal or higher level than the internal LogLevel of the LoggerPoint.
A detailed explanation how this internal LogLevel is set via the Logger Points tab of the ApplicationLogger is described in the chapter Change the log level of a logger point. The order of the LogLevels is defined in the ET_LogLevel enumeration if it is not intuitively understood.
If the internal LogLevel is set to for example, StatusMessage the messages which are sent from this point on are added to the LogMessage list, previous send messages are still ignored.