最近用log4net写入日志到mysql数据库,死活写不进去,就想能不能看log4net的错误记录,在网上一找,还真有:开启log4net的内部调试,作个记录:
<appSettings>
<add key="log4net.Internal.Debug" value="true"/>
</appSettings>
<system.diagnostics>
<trace autoflush="true">
<listeners>
<add
name="textWriterTraceListener"
type="System.Diagnostics.TextWriterTraceListener"
initializeData="C:\log4net.txt" />
</listeners>
</trace>
</system.diagnostics>
将这两个配置节放在<configuration>中
<configuration>
<configSections>
<sectionGroup name="common">
<section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
</sectionGroup>
</configSections>
<common>
<logging>
<!--2.此Adapter只输出到log4.net的配置文件所指定的地方-->
<factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net1213">
<!--FILE,FILE-WATCH,INLINE,EXTERNAL-->
<arg key="configType" value="FILE" />
<arg key="configFile" value="~/log4net.config" />
<!-- 指定log4net的配置文件名称 -->
<arg key="level" value="info" />
</factoryAdapter>
</logging>
</common>
<appSettings>
<add key="log4net.Internal.Debug" value="true"/>
</appSettings>
<system.diagnostics>
<trace autoflush="true">
<listeners>
<add
name="textWriterTraceListener"
type="System.Diagnostics.TextWriterTraceListener"
initializeData="C:\log4net.txt" />
</listeners>
</trace>
</system.diagnostics>
<connectionStrings>
<add name="MySQL" connectionString="server=.;database=*****;Uid=****;Pwd=****;" />
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="log4net" publicKeyToken="669e0ddf0bb1aa2a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.2.11.0" newVersion="1.2.11.0" />
</dependentAssembly>
</assemblyBinding>
</runtime> </configuration>
另log4net的mysql写法:
<connectionType value="MySql.Data.MySqlClient.MySqlConnection, MySql.Data, Version=6.9.5.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"/>
参照了此网页的评论:http://www.cnblogs.com/jimmyblog/archive/2008/08/18/1270665.html