Logging

Soya uses the log4net logging infrastructure to output log statements to a variety of sources. To see the log output or change the logging behavior, add a reference to the log4net.dll that ships with the Soya distribution and create a log4net configuration file.

It is important that the name of the log4net configuration file is the same name as your assembly but with .log4net appended. For example, if your assembly that is using Soya is called MyServiceApp.exe, then the log4net configuration file would be called MyServiceApp.exe.log4net. Please make sure that the log4net file you have just created is always copied to your output directory!

Further, for the above to work, you have to add the following attribute to your AssemblyInfo.cs file:

[assembly: XmlConfigurator(ConfigFileExtension = "log4net", Watch = true)] 

Finally, for the logging infrastructure to work properly, the first log statement has to be called from within your (not the Soya) assembly, i.e. just put something like log.Info("Starting program..."); at the beginning of your program.

Below is a simple example of a log4net configuration file that outputs log statements in different colors to a console:

<?xml version="1.0" encoding="utf-8" ?>
<log4net>
  <appender name="ConsoleAppender" type="log4net.Appender.ColoredConsoleAppender" >
    <mapping>
      <level value="DEBUG" />
      <foreColor value="White" />
    </mapping>
    <mapping>
      <level value="INFO" />
      <foreColor value="Yellow" />
    </mapping>
    <mapping>
      <level value="WARN" />
      <foreColor value="Red, HighIntensity" />
    </mapping>
    <mapping>
      <level value="ERROR" />
      <foreColor value="White, HighIntensity" />
      <backColor value="Red" />
    </mapping>
    <mapping>
      <level value="FATAL" />
      <foreColor value="White, HighIntensity" />
      <backColor value="Red" />
    </mapping>
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%date{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{1}:%method - %message%newline" />
    </layout>
  </appender>
  <root>
    <level value="DEBUG" />
    <appender-ref ref="ConsoleAppender" />
  </root>
</log4net>