我们在公司中使用数据库附加程序(AdoNetAppender)已有一段时间了。我们正在立即进行部署,并且看不到任何错误持续存在到数据库中。我们曾经认为数据库连接被防火墙阻止了,但是您已经可以看到它陷入了困境。
我添加了RollingFileAppender,FileAppender,并尝试使用bufferingForwarder,并尝试了stackoverflow绿色世界上的所有问题来解决此问题,并且绝对没有任何变化。我什至删除了对AdoNetAppender的引用,现在它根本不记录错误,而对于AdoNetAppender,它记录了两次错误-一次是AdoNetAppender,一次是FileAppender。
我的xml代码是:
<root>
<level value="ALL"/>
<appender-ref ref="RollingFileAppender"/>
<appender-ref ref="AdoNetAppender"/>
</root>
<appender name="AdoNetAppender">
<!--working xml. No need to post this information-->
</appender>
<appender name="BufferingForwarder" type="log4net.Appender.BufferingForwardingAppender">
<bufferSize value="5" />
<lossy value="false" />
<appender-ref ref="fileAppender" />
<!-- or any additional appenders or other forwarders -->
</appender>
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="logs\log4net.log"/>
<datePattern value="yyyy-MM-dd'-FULL.log'" />
<appendToFile value="true"/>
<preserveLogFileNameExtension value="true"/>
<rollingStyle value="Size"/>
<maximumFileSize value="250KB"/>
<maxSizeRollBackups value="-1"/>
<staticLogFileName value="false"/>
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%date [%thread] %-5level %logger - %message%newline"/>
</layout>
</appender>
我的c#代码是:
(使用Logger:ExceptionFilterAttribute)
private static ILog Log;
private static ILog FileLog;
private static bool _isConfigured = false;
private static void ConfigureLogger()
{
if (_isConfigured) return;
XmlConfigurator.Configure();
FileLog = LogManager.GetLogger("RollingFileAppender")
Log = LogManager.GetLogger("AdoNetAppender")
_isConfigured = true;
}
public static void Error(string message, Exception e) {
ConfigureLogger();
Log.Error(message, e);
}
public override void OnException(HttpActionExecutedContext context)
{
Error("Unexpected error occurred", context.Exception);
ConfigureLogger();
if (FileLog != null)
FileLog.Error("Unexpected Error Occurred", context.Exception);
}