Logging to the Windows Event Log


Description

Sitecore CMS uses the log4net library to output log statements to Sitecore log files in the “\Data\logs” folder according to the Sitecore “LogFolder” setting from the web.config file. 

By default, log4net is configured to use the “SitecoreLogFileAppender” appender. However, the log4net library includes other build-in appenders, such as the “EventLogAppender” appender.

The full list of supported appenders by log4net library can be found at the following link:
http://logging.apache.org/log4net/release/config-examples.html

The “EventLogAppender” appender is designed to log to the Windows Application Event Log on a workstation where Sitecore instance is deployed.

Solution

The recommended approach to configure Sitecore CMS to use the “EventLogAppender” appender would be the following:

  1. Modify your web.config file, under the “\configuration\log4net” element. Add the following lines:
    <appender name="EventLogAppender" type="log4net.Appender.EventLogAppender, Sitecore.Logging" >
      <param name="ApplicationName" value="Sitecore CMS" />
      <param name="Threshold" value="ERROR" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%4t %d{ABSOLUTE} %-5p %m%n" />
      </layout>
    </appender>
    Note: in the “ApplicationName” parameter you can specify the application name, which will be shown in the “Source” field of Windows Event Log.
    In the “Threshold” parameter, you can specify the log level that you would like to log to the Windows Application Event Log.
  2. Modify your web.config file under the “\configuration\log4net\root” element. Add the following line: 
    <appender-ref ref="EventLogAppender" />
  3. Run the “regedit.exe” tool to allow Sitecore CMS logging to the Windows Application Event Log files.
  4. In the Windows Registry, create the following registry key:
    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\eventlog\Application\Sitecore CMS
    Note: the registry key value must be the same as specified in the “ApplicationName” parameter for the “EventLogAppender” appender.
  5. In the “Sitecore CMS” registry key, create a string value with the “EventMessageFile” value name
    and the “\%SystemRoot%\Microsoft.NET\Framework<bitnes>\<version>\EventLogMessages.dll ” value data.
    <bitness> - x64 if the web site application pool is running in 64-bit mode, otherwise empty.
    <version> - .NET Framework version that the web site application pool is configured to use (v2.0.50727 or v4.0.30319).
  6. Restart the Sitecore CMS web application to apply the changes.
  7. If for some reason you cannot see the log information in the Windows Event Viewer, enable log4net internal debugging. Please take a look at the “How do I enable log4net internal debugging?” section.