Jeremy Davis
Jeremy Davis
Sitecore, C# and web development
Article printed from:

Logging patterns for Sitecore 6.6

Published 23 March 2015
Updated 25 August 2016
Logging Sitecore ~2 min. read

While working on the logging configuration for sending messages via email last week, I realised that all the documentation I could find for the element was for a newer version, and this wasn't helping me work out how to use it.

So with a bit of research, I've dug out the important values that can be used in case anyone else needs to configure log messages in older versions of Sitecore:

  • Thread identifer: %t The operating system identifier for the thread raising the log message
  • Date: %d The date at which the log message was created. Can be modified by appending a format parameter in curly braces. The code describes the set as being IS08601, ABSOLUTE and DATE, however the old log4j documentation implies any valid date-type format string could be used here.
  • Message priority level: %p The severity of the log message, when it was recorded.
  • Log identifer: %C Returns the fully qualified class name that raised the log message.
  • Line number: %L The source code line number for the method. This does not seem to display a value for messages logged by Sitecore itself.
  • Process identity: %W The windows username of the process identity running the code which logged the message.
  • AppDomain identifier: %a The identifier set when the AppDomain was created by IIS.
  • Reporting class: %c Similarly to %C, seems to return the fully qualified name of the class raising the log message.
  • Reporting method: %l and %M The name of the logging method that was called to record the message. %l returns the fully qualified method name, and %M just the name of the method called.
  • Log message: %m The full text of the log message that was recorded.
  • **Time taken to record the log message: %r Records the time difference (in milliseconds) between the time the logging event begins and the time the log event record is complete.
  • New line: %n Writes a line ending.
  • Mapped Diagnistic Context: %X / Nested Diagostic Context: %x These two patterns let you output custom data that has been recorded during the logging session. You specify what item from the internal log data collection you want by supplying its key in curly braces after the format specifier. e.g. "%X" These might be useful if you were writing your own custom log data, but as far as I can see from a bit of reflection-based investigation there's no data recorded here by default. There are some docs available for log4j which cover how this works.

If you need to output a % character, use %%.

Logging patterns can also include a column width format, by placing a number between the % and the pattern character. For example %4t will ensure the field occupies at least four characters and align it to the right of the space. Use a negative number to align to the left: %-5p.

Hopefully that'll be of help to someone other than me...

↑ Back to top