Skip to content

Commit

Permalink
Add log4net configuration example
Browse files Browse the repository at this point in the history
  • Loading branch information
rbezlepk committed Mar 3, 2016
1 parent 7141c4e commit cfdfd32
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
27 changes: 26 additions & 1 deletion Carbonator/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<configuration>
<configSections>
<section name="carbonator" type="Crypton.Carbonator.Config.CarbonatorSection, Crypton.Carbonator"/>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>

<!--
Expand Down Expand Up @@ -80,7 +81,31 @@
Be sure to set logType="log4net" above!
-->
<log4net>

<appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender">
<threshold value="ALL" />
<param name="File" value="carbonator.log" />
<param name="AppendToFile" value="true" />
<param name="encoding" value="utf-8" />
<param name="rollingStyle" value="Size" />
<param name="maximumFileSize" value="4MB" />
<param name="maxSizeRollBackups" value="4" />
<param name="PreserveLogFileNameExtension" value="true" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss}[%t] %-5p %m%n" />
</layout>
</appender>
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
<layout type="log4net.Layout.PatternLayout">
<param name="Header" value="[Header]\r\n" />
<param name="Footer" value="[Footer]\r\n" />
<param name="ConversionPattern" value="%d [%t] %-5p %m%n" />
</layout>
</appender>
<root>
<level value="INFO" />
<appender-ref ref="LogFileAppender" />
<appender-ref ref="ConsoleAppender"/>
</root>
</log4net>

</configuration>
2 changes: 2 additions & 0 deletions Carbonator/Log.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Crypton.Carbonator.Config;
using log4net;
using log4net.Config;
using System;
using System.Collections.Generic;
using System.Diagnostics;
Expand Down Expand Up @@ -42,6 +43,7 @@ static Log()

if (type == Types.Log4Net)
{
XmlConfigurator.Configure();
log4net = LogManager.GetLogger(typeof(Log));
}
}
Expand Down

0 comments on commit cfdfd32

Please sign in to comment.