November Happy Hour will be moved to Thursday December 5th.

Loading...
Area: Optimizely CMS
ARCHIVED This content is retired and no longer maintained. See the latest version here.

Recommended reading 

Logging into .NET Diagnostics Trace

There are two built-in logger factories for writing log messages from the EPiServer Log API to .NET Diagnostics Trace; the EPiServer.Logging.TraceLoggerFactory and the EPiServer.Logging.TraceSourceLoggerFactory.

EPiServer.Logging.TraceLoggerFactory

The EPiServer.Logging.TraceLoggerFactory logger redirects all log messages to diagnostics trace.

  • EPiServer Critical and Error Log level maps to the system diagnostics trace error level, 
  • EPiServer Warning Log API level maps to the system diagnostics trace warning level, 
  • EPiServer Information Log API level maps to the system diagnostics trace Information level and
  • EPiServer Debug and Trace Log API level maps to the system diagnostics debug output.

You enable the EPiServer.Logging.TraceLoggerFactory like this:

<appSettings>
     <add key="episerver:LoggerFactoryType" value="EPiServer.Logging.TraceLoggerFactory" />
</appSettings>

Or from the episerver.framework section like this:

<episerver.framework loggerFactoryType="EPiServer.Logging.TraceLoggerFactory">

EPiServer.Logging.TraceSourceLoggerFactory

The EPiServer.Logging.TraceSourceLoggerFactory redirects all log messages to diagnostics trace source. In this implementation each logger name has its own source switch trace.

  • EPiServer Critical Log API level maps to the system diagnostics trace source critical level,
  • EPiServer Error Log API level maps to the system diagnostics trace source error level,
  • EPiServer Warning Log API level maps to the system diagnostics trace source warning level,
  • EPiServer Information Log API level maps to the system diagnostics trace source Information level and
  • The rest of EPiServer Log API level maps to the system diagnostics Verbose.

You can enable the EPiServer.Logging.TraceSourceLoggerFactory like this:

<appSettings>
     <add key="episerver:LoggerFactoryType" value="EPiServer.Logging.TraceSourceLoggerFactory" />
</appSettings>

Or from the episerver.framework section like this:

<episerver.framework loggerFactoryType="EPiServer.Logging.TraceSourceLoggerFactory">

By default, the logging level is set to the Error level. If you need to log lower levels than the Error level you need to configure it in the system.diagnostics section like this:

<system.diagnostics>
    <sources>
       <source name="logger name" switchName="logger name" switchType="System.Diagnostics.SourceSwitch"/>
    </sources>
    <switches>
       <add name="logger name" value="Verbose" />
    </switches>
  </system.diagnostics>

Registering Logger Factory via configuration

To register a logger factory via configuration, you need to add the logger factory type in the appsettings  section:

<appSettings>
     <add key="episerver:LoggerFactoryType" value="the custom logger factory type" />
</appSettings>

Or from the episerver.framework section:

 <episerver.framework loggerFactoryType="the custom logger factory type">

Note: Remember that the appsetting  section value always has higher priority to be used than the episerver.framework section value.

Do you find this information helpful? Please log in to provide feedback.

Last updated: Jul 14, 2016

Recommended reading