对于性能问题,log4net的好处是您可以随时对其进行配置以查看您的应用程序使用log4net是否受到瓶颈,以及: 1)解决该解决方案你自己或 2)找到一个没有这个瓶颈的日志框架。
我不知道你的应用程序太多了,但从粗略浏览log4net源我发现NextCheckDate()
函数正在调用每个void Append(LoggingEvent loggingEvent)
。我在下面包含了NextCheckDate的一部分源代码,我可以确定这在高容量日志记录场景中导致性能问题。
protected DateTime NextCheckDate(DateTime currentDateTime, RollPoint rollPoint){
// Local variable to work on (this does not look very efficient)
DateTime current = currentDateTime;
// Do different things depending on what the type of roll point we are going for is
switch(rollPoint)
{
case RollPoint.TopOfMinute:
current = current.AddMilliseconds(-current.Millisecond);
current = current.AddSeconds(-current.Second);
current = current.AddMinutes(1);
break;
case RollPoint.TopOfDay:
current = current.AddMilliseconds(-current.Millisecond);
current = current.AddSeconds(-current.Second);
current = current.AddMinutes(-current.Minute);
current = current.AddHours(-current.Hour);
current = current.AddDays(1);
break;
case RollPoint.TopOfMonth:
current = current.AddMilliseconds(-current.Millisecond);
current = current.AddSeconds(-current.Second);
current = current.AddMinutes(-current.Minute);
current = current.AddHours(-current.Hour);
current = current.AddMonths(1);
break;
}
return current;}
为您的应用程序可能会缓存的下一个翻转时间提前只做每个Append
任何需要每天记录5-10GB的网站(除IIS日志外)在我看来都有一个设计缺陷。 Log4Net并非设计成审计员 – 2009-06-11 14:28:56
关于文件在一天结束时滚动的有趣提示。它在Windows 7(IIS 7.5)上运行良好,但是当我们切换到Win 2008 Server(也是IIS 7.5)时,我们开始看到大量数据被破坏。昨天的10MB日志文件被替换为几个日志行。任何想法为什么? – Sire 2010-11-10 14:38:04