This project has moved and is read-only. For the latest updates, please go here.

RollingXmlTraceListener Class

Trace listener that writes E2ETraceEvent XML fragments to a text file, rolling to a new file based on a filename template (usually including the date).


Install via NuGet:


A rolling log file is achieved by including the date in the filename, so that when the date changes a different file is used.

Available tokens are DateTime (a UTC DateTimeOffset) and LocalDateTime (a local DateTimeOffset), as well as ApplicationName, ProcessId, ProcessName and MachineName. These use standard .NET format strings, e.g. "Trace{DateTime:yyyyMMddTHH}.svclog" would generate a different log name each hour.

The E2ETraceEvent XML fragment format can be read by the Service Trace Viewer tool.

Config Attributes

Attribute Description
initializeData Template file path and name to log to, using replacement tokens to rotate based on the date; the default template is "{ApplicationName}-{DateTime:yyyy-MM-dd}.svclog", which rotates on a daily basis.
traceOutputOptions Not used.

Path Template Parameters

Parameter Description
{ApplicationName} Name of the current executable, without the extension.
{DateTime} DateTimeOffset of the log event, in the UTC (+0) timezone.
{LocalDateTime} DateTimeOffset of the log event, in the local timezone.
{MachineName} Local computer name, from Environment.MachineName.
{ProcessId} Id of the current process, from Process.GetCurrentProcess().
{ProcessName} Name of the current process, from Process.GetCurrentProcess().

Example Config

<?xml version="1.0" encoding="utf-8" ?>
      <add name="rollingxml"
        type="Essential.Diagnostics.RollingXmlTraceListener, Essential.Diagnostics.RollingXmlTraceListener"
        initializeData="{ApplicationName}-{DateTime:yyyyMMdd}.svclog" />
      <source name="ExampleSource" switchValue="All">
          <clear />
          <add name="rollingxml" />

Example Output

Output files from multiple processes can be opened in the Service Trace Viewer tool and correlated across boundaries:

RollingXmlTraceListener Example Output

Config Template

<add name="rollingxml"
  type="Essential.Diagnostics.RollingXmlTraceListener, Essential.Diagnostics.RollingXmlTraceListener"

Last edited Feb 6 at 5:50 AM by sgryphon, version 4


geirs73 Aug 15, 2012 at 12:20 AM 
It would be nice if the rolling trace listeners also worked with template parameters as a part of the path, not just the file name. If there is a template parameter as a part of the path, the logger should create the directory where the log file should be put, unless it already exists. Now it just fails. (I'm using version 1.1.20103).