我通过以下方式使用Log4Net:
private static readonly ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
public static void Init(Level logLevel, bool autoFlush, string logTextFile)
{
var hierarchy = (Hierarchy) LogManager.GetRepository();
var patternLayout = new PatternLayout();
patternLayout.ConversionPattern = "%date{yyyy-MM-dd HH:mm:ss.fff} %-7level [%thread] %message%newline";
patternLayout.ActivateOptions();
var roller = new RollingFileAppender();
roller.AppendToFile = false;
roller.File = logTextFile;
roller.Layout = patternLayout;
roller.MaxSizeRollBackups = 3;
roller.MaxFileSize = 10000000;
roller.RollingStyle = RollingFileAppender.RollingMode.Size;
roller.StaticLogFileName = true;
roller.ImmediateFlush = autoFlush;
roller.ActivateOptions();
hierarchy.Root.AddAppender(roller);
hierarchy.Root.Level = Level.Info;
hierarchy.Configured = true;
}
那很好。
现在我想添加Log4Net.Async,但是我完全不知道如何通过代码添加它。有人可以给我一个例子吗?