This is what you should put into your application's config (Web.config in my case) to the <log4net> section:
<appender name="SomeLogFileAppender" type="log4net.Appender.FileAppender">
<file type="log4net.Util.PatternString" >
<converter>
<name value="hostname" />
<type
value="MyNamespace.MySubNamespace.HostnamePatternConverter,MyNamespace" />
</converter>
<conversionPattern
value="debuglog-%hostname{LocalApplicationData}.txt" />
</file>
<appendToFile value="true" />
<rollingStyle value="Date" />
<datePattern value="yyyyMMdd" />
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level - %message%newline" />
</layout>
</appender>
And then the code snippet which implements HostnamePatternConverter:
using log4net;
using System;
namespace MyNamespace.MySubNamespace {...
public class HostnamePatternConverter : log4net.Util.PatternConverter
{
protected override void Convert(TextWriter writer, object state)
{
writer.Write(Environment.MachineName);
}
}...
}
No comments:
Post a Comment