Added basic log4net config file

This commit is contained in:
Torben Nehmer 2016-11-19 22:35:33 +01:00
parent 04bfca789b
commit 9f324759cd
3 changed files with 48 additions and 1 deletions

View File

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8" ?>
<log4net>
<!-- A1 is set to be a ConsoleAppender -->
<appender name="Console" type="log4net.Appender.ColoredConsoleAppender">
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%-5timestamp [%thread] %-5level %logger - %message%newline" />
</layout>
<mapping><level value="ERROR" /><foreColor value="Red, HighIntensity" /></mapping>
<mapping><level value="WARN" /><foreColor value="Yellow, HighIntensity" /></mapping>
</appender>
<appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
<file value="vcs.log" />
<appendToFile value="true" />
<maximumFileSize value="100KB" />
<maxSizeRollBackups value="2" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger - %message%newline" />
</layout>
</appender>
<!-- Set root logger level to DEBUG and its only appender to A1 -->
<root>
<level value="DEBUG" />
<appender-ref ref="Console" />
<appender-ref ref="RollingFile" />
</root>
</log4net>

View File

@ -52,6 +52,9 @@
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="Config Files\log4net.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

View File

@ -3,13 +3,28 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using log4net;
namespace NAV_Source_Control
namespace NAVSCM
{
class Program
{
private static readonly ILog log = LogManager.GetLogger(typeof(Program));
static void Main(string[] args)
{
log4net.Config.XmlConfigurator.ConfigureAndWatch(new System.IO.FileInfo("Config Files\\log4net.config"));
log.Info("Starting up...");
log.Debug("Debug");
log.Warn("Warn");
log.Error("Error");
log.Fatal("Fatal");
log.Info("Shutting down...");
Console.ReadLine();
}
}
}