我的问题是,在开发和测试环境中,代码工作正常,但是当它发布到生产环境时,它也不能正常工作。
在发布之后,它将记录第一个用户请求,该请求在INFO级别时约为9个不同的日志条目。在最初的9之后,在服务器重新启动之前不会再记录任何内容。我现在只有这个裸代码在生产中,它仍然显示相同的行为
有什么可能导致这种情况的建议吗?
配置:
<log4net>
<root>
<level value="INFO" />
<appender-ref ref="AdoNetAppender" />
<appender-ref ref="EventLogAppender" />
</root>
<appender name="AdoNetAppender" type="log4net.Appender.AdoNetAppender">
<bufferSize value="1" />
<reconnectonerror value="true" />
<connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<connectionString value="Data Source=SQLHOTELL-FT,10433;Initial Catalog=BEKS;Integrated Security=True" />
<commandText value="INSERT INTO Log ([Date],[Thread],[Level],[Logger],[Message],[Exception],[UserId]) VALUES (@log_date, @thread, @log_level, @logger, @message, @exception, @userid)" />
<filter type="log4net.Filter.LevelRangeFilter">
<levelMin value="INFO" />
<levelMax value="FATAL" />
</filter>
<parameter>
<parameterName value="@log_date"/> <dbType value="DateTime"/> <layout type="log4net.Layout.RawTimeStampLayout"/>
</parameter>
<parameter>
<parameterName value="@thread"/> <dbType value="String"/> <size value="255"/> <layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%thread"/>
</layout>
</parameter>
<parameter>
<parameterName value="@log_level"/> <dbType value="String"/> <size value="50"/> <layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%level"/>
</layout>
</parameter>
<parameter>
<parameterName value="@logger"/> <dbType value="String"/> <size value="255"/> <layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%logger"/>
</layout>
</parameter>
<parameter>
<parameterName value="@message"/> <dbType value="String"/> <size value="4000"/> <layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%message"/>
</layout>
</parameter>
<parameter>
<parameterName value="@exception"/> <dbType value="String"/> <size value="2000"/> <layout type="log4net.Layout.ExceptionLayout"/>
</parameter>
<parameter>
</appender>
<appender name="EventLogAppender" type="log4net.Appender.EventLogAppender" >
<applicationName value="BeksWebInterface" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
</layout>
<filter type="log4net.Filter.LevelRangeFilter">
<levelMin value="FATAL" />
<levelMax value="FATAL" />
</filter>
</appender>
</log4net>
代码:
public static class Log
{
private static ILog log;
public static void CreateLogEntry(string message)
{
try
{
log = LogManager.GetLogger(typeof(Log));
log4net.Config.XmlConfigurator.Configure();
log.Info(message);
}
catch
{
}
}
}
答案 0 :(得分:1)
为什么首先获取记录器然后配置log4net?通常它是相反的方式。 E.g。
// Configure log4net
var info = new FileInfo("myapp.log4net");
log4net.Config.XmlConfigurator.Configure(info);
// get the logger
var logger = LogManager.GetLogger(this.GetType());