我的log4net配置中有多个appender,一个用于记录到文件,另一个用于存储过程。我能够看到记录到文件,但只有在我点击"停止网站"后才会显示SQL数据,见下图:
所以我得出的结论是,我可能不得不关闭'通过执行以下操作实例:log4net.LogManager.GetLogger("SearchParamsLogger").Logger.Repository.Shutdown();
但是这样做似乎也关闭了另一个记录器。 如何只关闭一个记录器?
我有以下logger
块:
<logger name="SearchParamsLogger">
<level value="DEBUG" />
<appender-ref ref="LogSearchParams" />
</logger>
<logger name="FileLogger">
<level value="DEBUG" />
<appender-ref ref="LogFile" />
</logger>
我的.config中有以下appender:
<appender name="LogSearchParams" type="log4net.Appender.AdoNetAppender">
<bufferSize value="100" />
<connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<connectionString value="data source=MyServer\SQLEXPRESSPC;initial catalog=MyDatabase;integrated security=false;persist security info=True;User ID=DBUser;Password=MyPassword" />
<commandText value="InsertIManNrlLog" />
<commandType value="StoredProcedure" />
<parameter>
<parameterName value="@UserName"/>
<dbType value="String" />
<size value="255" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%property{uname}" />
</layout>
</parameter>
<parameter>
<parameterName value="@ObjectId" />
<dbType value="String" />
<size value="4000" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%message" />
</layout>
</parameter>
<parameter>
<parameterName value="@DeleteSpan" />
<dbType value="Int32" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%property{deleteSpan}" />
</layout>
</parameter>
<parameter>
<parameterName value="@LogLevel" />
<dbType value="String" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%level" />
</layout>
</parameter>
</appender>
<appender name="LogFile" type="log4net.Appender.FileAppender">
<file value="application.log"/>
<appendToFile value="true"/>
<layout type="log4net.Layout.PatternLayout">
<header value="Logging Start 
"/>
<footer value="Logging End 
"/>
<conversionPattern value="%date | [%thread] %-5level %logger: %message%newline"/>
</layout>
</appender>