我必须像这样记录线程上下文属性:
string logFilePath = AppDomain.CurrentDomain.BaseDirectory + "log4netconfig.xml";
FileInfo finfo = new FileInfo(logFilePath);
log4net.Config.XmlConfigurator.ConfigureAndWatch(finfo);
ILog logger = LogManager.GetLogger("Exception.Logging");
log4net.ThreadContext.Properties["MESSAGE"] = exception.Message;
log4net.ThreadContext.Properties["MODULE"] = "module1";
log4net.ThreadContext.Properties["COMPONENT"] = "component1";
logger.Debug("test");
配置文件是:
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,Log4net"/>
</configSections>
<log4net>
<logger name="Exception.Logging" level="Debug">
<appender-ref ref="AdoNetAppender"/>
</logger>
<appender name="AdoNetAppender" type="log4net.Appender.AdoNetAppender">
<connectionString value="Data Source=xe;User ID=test;Password=test;" />
<connectionType value="System.Data.OracleClient.OracleConnection, System.Data.OracleClient, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<bufferSize value="10000"/>
<commandText value="Log_Exception_Pkg.Insert_Log" />
<commandType value="StoredProcedure" />
<parameter>
<parameterName value="@p_Error_Message" />
<dbType value="String" />
<size value="255" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%property{MESSAGE}"/>
</layout>
</parameter>
<parameter>
<parameterName value="@p_Module" />
<dbType value="String" />
<size value="225" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%property{MODULE}"/>
</layout>
</parameter>
<parameter>
<parameterName value="@p_Component" />
<dbType value="String" />
<size value="225" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%property{COMPONENT}"/>
</layout>
</parameter>
</appender>
</log4net>
</configuration>
但它没有将它们插入数据库。我怎样才能让它工作?