Configuration samples


Data for channel "Main" will be written to categories with ids 1 and 2 both.
Category 1 will try to send data to WCF service. If it will fail data will be written to file system. If it will fail data will be written to console.
Category 2 will write data to console.

Data for channel "Exception" will be written to categories with ids 1 and 3 both.
Category 1 will try to send data to WCF service. If it will fail data will be written to file system. If it will fail data will be written to console.
Category 2 will try to write data to event log. If it will fail data will be written to console.

<?xml version="1.0"?>
<configuration>
  <configSections>
    <section name="logManager" type="NSoft.Log.Core.LogManagerConfigurationHandler, NSoft.Log.Core"/>
  </configSections>

  <logManager>
    <!-- Define and configure log writers -->
    <logWriters switchTime="60000">
      <!-- WCF Writer -->
      <add id="1" type="NSoft.Log.Writers.Wcf.WcfLogWriter, NSoft.Log.Writers" configurationType="NSoft.Log.Writers.Wcf.WcfLogWriterSettings, NSoft.Log.Writers">
        <configuration>
          <endpointName>WcfLogWriter</endpointName>
        </configuration>
      </add>
      <!-- File Writer -->
      <add id="2" type="NSoft.Log.Writers.File.FileLogWriter, NSoft.Log.Writers" configurationType="NSoft.Log.Writers.File.FileLogWriterSettings, NSoft.Log.Writers">
        <configuration>
          <channelFileTemplate>{ChannelName}.{TimeStamp}.log</channelFileTemplate>
          <outputDirectory>./logs/</outputDirectory>
          <recreateTime>60000</recreateTime>

          <mappings>
            <add channelName="Main" value="console.{TimeStamp}.log"/>
          </mappings>
        </configuration>
      </add>
      <!-- EventLog Writer -->
      <add id="3" type="NSoft.Log.Writers.EventLog.EventLogWriter, NSoft.Log.Writers" configurationType="NSoft.Log.Writers.EventLog.EventLogWriterSettings, NSoft.Log.Writers">
        <configuration>
          <dataDelimeter>&#9;</dataDelimeter>
          <entryType>Information</entryType>
          <machineName>.</machineName>
          <logName>MyLog</logName>
          <dataMappings>
            <add channelName="Exception" category="2" event="1212" entryType="Error" message="DateTime: {0}&#13;&#10;Message:&#13;&#10;{1}&#13;&#10;Stack:&#13;&#10;{2}" />
          </dataMappings>

          <mappings>
            <add channelName="Information" value="Info"/>
          </mappings>
        </configuration>
      </add>
      <!-- Console Writer -->
      <add id="4" type="NSoft.Log.Writers.Console.ConsoleLogWriter, NSoft.Log.Writers"/>
    </logWriters>

    <!-- Define categories -->
    <categories>
      <!-- Common Category -->
      <add id="1">
        <logWriters>
          <add id="1" priority="11"/>
          <add id="2" priority="10"/>
          <add id="4" priority="9"/>
        </logWriters>
        <channels>
          <add name="Main"/>
          <add name="Exception"/>
        </channels>
      </add>
      <!-- Category for console output -->
      <add id="2">
        <logWriters>
          <add id="4" priority="10"/>
        </logWriters>
        <channels>
          <add name="Main"/>
        </channels>
      </add>
      <!-- Category writes data to event log -->
      <add id="3">
        <logWriters>
          <add id="3" priority="10"/>
          <add id="4" priority="9"/>
        </logWriters>
        <channels>
          <add name="Exception"/>
        </channels>
      </add>
    </categories>
  </logManager>
</configuration>

Last edited Apr 17, 2011 at 9:16 PM by Tesh, version 2