Setting up the log configurations
Learn to set up the log configuration for troubleshooting.
Logging is configured by adding element <Logging/>
to the element <update.lib>
in the configuration XML file (for example, settings.xml
or
app.config
).
Logging consists of 3 components:
- Formatter — specifies how the lines in the log is formatted.
- Writer — specifies where the log messages is written (a file, the event log, a database, ...).
- Channel — combines a formatter with a writer.
Log Writers – specifies where the log messages is written (a file, the event log, a database, ...)
Log writers are of two types:
- FileLogWriter— writes log messages into files in the file system
The XML attributes supported by FileLogWriter are listed in the table below:
XML Attribute
Description
Name
The name of the log writer. This name has to be specified as XML attribute
writerName
on the<Channel />
element. This is a mandatory attribute.type
The class name and assembly implementing the file log writer. Default value is
update.Lib.Logging.Writers.FileLogWriter,update.Lib
. It is a mandatory attribute.filePath
The path to the log file. You can use environment variables. Relative paths relatives to the applications base directory. It is a mandatory attribute.
maxSizeKB
The maximum size of the log file in KB. What happens if this limit is exceed can be defined by XML attribute
rollingMode
.closeOnIdleTimeout
The number of seconds after which the log file is closed when being idle. Use the
rollingMode
attribute to define when backup log files is created.- "None" - No backup log files is created
- "Startup" - A new backup log file is created every time the process starts.
- "Size" - A new backup log files is created when the size specified in maxSizeKB is exceeded.
- "Date" - A new backup log file is created for every day.
Multiple values can be combined using "," (for example, "Startup,Size")
encoding
Specify the encoding (default is the operating system's current ANSI codepage). Common values are "utf-8" and "utf-16". See http://msdn.microsoft.com/de-de/library/system.text.encoding.aspx for a complete list.
compressBackup
If "True" the backup log files is compressed using gzip (default "False").
maxBackups
The maximum number of backup log files that is created. If this limit is exceeded the oldest log files is deleted.
backupFolder
The folder where backup log files is stored. You can use environment variables. Relative paths relates to the applications base directory.
autoFlush
If "True" (default) the log file is flushed after every write. This ensures that in case the logging process is terminated all the log messages are in the file.
includeDateInBackupFileName
If "True" a date is included in the backup file name. If "False" (default) the backup files is numbered consecutively.
A sample usage of the FileLogWriter element is shown below:
... <Logging> ... <Writer name="fileLogWriter" type="update.Lib.Logging.Writers.FileLogWriter,update.Lib" filePath="myapplication.log" /> ... </Logging> ...
- SysLogWriter— sends log messages over a network using TCP or UDP
packets.
Though it does not contain any SysLog-specific logic, it is designed to be used in combination with some flavor of the SysLogFormatter.
The XML attributes supported by SysLogWriter are listed in the table below:
XML Attribute
Description
Name
The name of the log writer. This name has to be specified as XML attribute
writerName
on the<Channel />
element.type
The class name and assembly implementing the Sys log writer. Default value is
update.Lib.Logging.Writers.SysLogWriter,update.Lib
.filePath
The path to the log file. You can use environment variables. Relative paths relates to the applications base directory.
host
The hostname or IP address of the target for the communication.
port
The port number of the target for the communication.
protocol
The communication protocol to be used (tcp or udp are supported).
A sample usage of the FileLogWriter element is shown below.
... <Logging> ... <Writer name="mySysLogWriter" type="update.Lib.Logging.Writers.SysLogWriter,update.Lib" host="syslogserver.acme.com" port="514" protocol="udp" /> ... </Logging> ...
Log Formatters – specifies how the lines in the log is formatted.
You can specify the formats of the log messages using the log formatter elements. The following elements are available:
DefaultLogFormatter
The DefaultLogFormatter is a generic formatter. The following sample shows an example of its usage:
... <Logging> ... <Formatter name="myFormatter" type="update.Lib.Logging.Formatters.DefaultLogFormatter,update.Lib" /> ... </Logging> ...
The XML attributes supported by DefaultLogFormatter element are listed in the table below:
XML Attribute |
Description |
---|---|
Name |
The name of the log writer. This name has to be specified as XML
attribute |
logDate |
If "true" the timestamp is written to the log file. |
logMillis |
If "true" the timestamp including milliseconds is written to the log file. In this case the setting for logDate is ignored. |
logTicks |
If "true" the tick count is written to the log file. |
logProcessId |
If "true" the process ID of the current process is written to the log file. |
logThreadId |
If "true" the ID of the current thread is written to the log file. |
logFacility |
If "true" the facility is written to the log file. |
logLevelFormat |
Defines if and how the current log level is written to the log file.
|
logException |
If "true" exceptions is written to the log file. |
logMemory |
If "true" the memory consumed by the current process is written to the log file. |
logCpu |
If "true" the CPU utilization by the current process is written to the log file. |
logUser |
If "true" the name of the current user is written to the log file. |
WebSysLogFormatter
The web SysLog formatter formats the messages in a web context so that they can be interpreted by a SysLog server. Apart from the standard set of XML attributes it supports the following:
XML Attribute |
Description |
---|---|
type |
The class name and assembly implementing the sys log formatter. This has
attribute has to be set to
|
maxMessageLength |
The character limit for the message. Some SysLog servers (and actually
the original SysLog standard as well) may limit the length of the
message, in which case this setting can be used to make sure that our
message won't be rejected.
Note: If the message exceeds the specified
length, it is truncated.
|
The following sample shows the usage of WebSysLogFormatter element:
... <Logging> ... <Formatter name="myFormatter" type="update.Web.Logging.WebSysLogFormatter,update.Web" /> ... </Logging> ...
Channel
A channel element combines a formatter element and a writer element. A channel element defines how the messages are written (using the formatter elements) and where to write the log messages (using the writer elements).
The following code example, shows the usage of a Channel element:
... <Logging> ... <Channel logLevel="Warning" writerName="myLogWriter" formatterName="myLogFormatter" /> ... </Logging> ...
The Channel element supports the following XML attributes:
XML Attribute |
Description |
---|---|
logLevel |
Defines how verbose this log channel is (default "Debug"). Possible values are: NoLogging; Emergency; Alert; Critical; Error; Warning; Notice; Info; and Debug. |
writerName |
The name of the writer used by this channel. A writer with this name has to be defined! |
fallbackWriterName |
The name of the fallback writer used by this channel. A writer with this name has to be defined! It is temporarily used in case of a failure of the default writer. |
fallbackTimeout |
Timeout period after which an attempt is made to reinitialize the writer after it has failed and has been replaced by the fallback writer (if any). The value has to be specified as a .NET-compatible TimeSpan, e.g. for 5 minutes the value would be 0:05, for 10 seconds 0:00:10. The default value is 5 minutes. |
formatterName |
The name of the formatted used by this channel. A formatted with this name has to be defined! |
facilityFilter |
Only log messages whose facility matches this filter is written to the channel. This filter has to be specified as a regular expression. |
facilityFilterExclude |
Log messages whose facility matches this filter is *NOT* written to the channel. This filter has to be specified as a regular expression. |
messageFilter |
Only log messages whose message text matches this filter is written to the channel. This filter has to be specified as a regular expression. |
messageFilterExclude |
Log messages whose message text matches this filter is *NOT* written to the channel. This filter has to be specified as a regular expression. |