Loading...

Last updated: Oct 27 2016

Area: Episerver CMS Applies to versions: 10 and higher
Other versions:

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.

Note: In Episerver DXC Service, all Episerver logs are redirected into .NET Diagnostic Trace, as long as the code uses the Episerver logging abstraction EPiServer.Logging.LogManager. If you are using log4net and deploying in DXC Service, replace log4net with EPiServer.Logging. See also Logging for more information on switching logging APIs.

EPiServer.Logging.TraceLoggerFactory

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

Episerver log level maps to 
Episerver Critical and Error Log system diagnostics trace error level
Episerver Warning Log API  system diagnostics trace warning level
Episerver Information Log API  system diagnostics trace Information level
Episerver Debug and Trace Log API not logged

You enable EPiServer.Logging.TraceLoggerFactory like this:

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

Or from the episerver.framework section like this:

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

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 log level maps to 
Episerver Critical Log API level system diagnostics trace source critical level
Episerver Error Log API level system diagnostics trace source error level
Episerver Warning Log API level  system diagnostics trace source warning level
Episerver Information Log API level  system diagnostics trace source Information level
Episerver Debug and Trace Log API system diagnostics Verbose

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

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

Or from the episerver.framework section like this:  

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

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 episerver.framework section:

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

Note: The appsetting section value always has a higher priority than the episerver.framework section value.


Do you have feedback on this documentation? Send an email to documentation@episerver.com. For development-related questions and discussions, refer to our Forums on https://world.episerver.com/forum/