首页 新闻 会员 周边 捐助

log4net无法插入到mysql数据库

0
悬赏园豆:60 [已解决问题] 解决于 2018-05-28 10:56

log4net配置文件

<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>  

assembly.cs文件

[assembly: AssemblyTitle("test")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("test")]
[assembly: AssemblyCopyright("版权所有(C)  2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("e33abc54-605a-47da-b0eb-5fea9b821bc9")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: log4net.Config.XmlConfigurator(ConfigFile = "Log4Net.config", Watch = true)]

global.asax文件

namespace test
{
    public class MvcApplication : System.Web.HttpApplication
    {
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            log4net.Config.XmlConfigurator.Configure());
        }
    }
}

homecontroller.cs

        public ActionResult Index()
        {
            log4net.ILog log = log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
            log.Error("123456");
            return View();
        }

mysql.data  log4net也都引用了并且都在bin文件下

问题补充:

写入文件是正常的,就是无法写入mysql数据库

sooke的主页 sooke | 初学一级 | 园豆:52
提问于:2018-05-28 10:11
< >
分享
最佳答案
1
收获园豆:60
dudu | 高人七级 |园豆:30757 | 2018-05-28 10:30

  <connectionType value="MySql.Data.MySqlClient.MySqlConnection, MySql.Data, Version=8.0.11.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />

我已经改成了项目安装的mysql.data的版本号,并且在bin目录下也可以找到这个版本的mysql.data.dll文件,还是无法插入到数据库

sooke | 园豆:52 (初学一级) | 2018-05-28 10:37

@sooke: 建议在代码中用同样的连接字符串写数据库测试一下

dudu | 园豆:30757 (高人七级) | 2018-05-28 10:43

@dudu: 找到问题了,主机不支持ssl连接,SslMode = None加上这行就好了,多谢!

sooke | 园豆:52 (初学一级) | 2018-05-28 10:56

@sooke: 这一串加在哪里,我遇到了跟你同样的问题

SportSky | 园豆:188 (初学一级) | 2020-09-23 11:23
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册