首页 新闻 搜索 专区 学院

log4net无法插入mysql数据库

0
悬赏园豆:50 [已关闭问题] 关闭于 2018-05-28 10:12

<configuration> 
<configSections> 
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" /> 
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections> 
<log4net> 
<appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender,log4net"> 
<param name="File" value="Log\\LogInfo\\" /> 
<param name="AppendToFile" value="true" /> 
<param name="MaxSizeRollBackups" value="100" /> 
<param name="MaximumFileSize" value="10240KB" /> 
<param name="StaticLogFileName" value="false" /> 
<param name="RollingStyle" value="Date" /> 
<param name="DatePattern" value="yyyy-MM-dd.TXT" /> 
<param name="CountDirection" value="-1" /> 
<layout type="log4net.Layout.PatternLayout"> 
<param name="ConversionPattern" value=" 【时间】:%d%n 【级别】:%p%n 【类名】:%c%n 【线程ID】: %thread %n 【文件地址】:%F 第%L行%n 【日志内容】:%m%n 【日记详细】:%exception %n---------------------------------------------------------------------------------------------------------------%n" /> 
</layout> 
</appender> 
<appender name="ADONetAppender" type="log4net.Appender.ADONetAppender"> 
<bufferSize value="1" /> 
<param name="ConnectionType" value="MySql.Data.MySqlClient.MySqlConnection, MySql.Data" />
<param name="ConnectionString" value="server=120.78.75.199;database=logtest;user id=root;password=4511027;port=3306;" /> 
<commandText value="INSERT INTO xlog (Date,Thread,Level,logger,Message,Exception) VALUES (@log_date, @thread, @log_level, @logger, @message, @exception)" /> 
<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="%t"/> 
</layout> 
</parameter> 
<parameter> 
<parameterName value="@log_level"/> 
<dbType value="String"/> 
<size value="50"/> 
<layout type="log4net.Layout.PatternLayout"> 
<conversionPattern value="%p"/> 
</layout> 
</parameter> 
<parameter> 
<parameterName value="@logger"/> 
<dbType value="String"/> 
<size value="50"/> 
<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="%m"/> 
</layout> 
</parameter> 
<parameter> 
<parameterName value="@exception"/> 
<dbType value="String"/> 
<size value="2000"/> 
<layout type="log4net.Layout.ExceptionLayout"> 
<conversionPattern value="%exception"/> 
</layout> 
</parameter> 
</appender> 
<root> 
<level value="ALL" /> 
<appender-ref ref="LogFileAppender"/> 
<appender-ref ref="ADONetAppender"/> 
</root> 
</log4net> 
</configuration>

 

写入文件没问题,就是无法插入到数据库,log4net mysql.data也都引用了

问题补充:

assembly也添加了

[assembly: log4net.Config.XmlConfigurator(ConfigFile = "Log4Net.config", Watch = true)]

 

global.asax

log4net.Config.XmlConfigurator.Configure(new System.IO.FileInfo("Log4Net.config"));

sooke的主页 sooke | 初学一级 | 园豆:52
提问于:2018-05-28 09:51
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册