具有ms访问权限的log4net记录器配置

时间:2019-02-12 03:05:45

标签: c# ms-access-2007 log4net

我的代码似乎可以正常工作,但是它没有向日志文件中写入任何内容,我编辑了文件的位置,但是仍然无法正常工作,我不知道我的错误在哪里,因为它不会弹出      我的这是我的应用程序配置的内容

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">

<supportedRuntime version="v4.0"/>

<configSections>
  <section name ="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
</configSections>

<log4net>
  <root>
  <level value="ALL"></level>
  <appender-ref ref ="AdoNetAppender"></appender-ref>
  </root>
  <appender name="AdoNetAppender_Access" type="log4net.Appender.AdoNetAppender">
    <connectionString value="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Toshiii\Desktop\V#\Logs.accdb;User Id=;Password=;" />
    <commandText value="INSERT INTO Log ([Date],[Thread],[Level],[Logger],[Message]) VALUES (@log_date, @thread, @log_level, @logger, @message)" />
    <parameter>
      <parameterName value="@log_date" />
      <dbType value="String" />
      <size value="255" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date" />
      </layout>
    </parameter>
    <parameter>
      <parameterName value="@thread" />
      <dbType value="String" />
      <size value="255" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%thread" />
      </layout>
    </parameter>
    <parameter>
      <parameterName value="@log_level" />
      <dbType value="String" />
      <size value="50" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%level" />
      </layout>
    </parameter>
    <parameter>
      <parameterName value="@logger" />
      <dbType value="String" />
      <size value="255" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%logger" />
      </layout>
    </parameter>
    <parameter>
      <parameterName value="@message" />
      <dbType value="String" />
      <size value="1024" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%message" />
      </layout>
    </parameter>
  </appender>
</log4net>

我系统代码的内容是

using log4net;
private void q_Click(object sender, EventArgs e)
    {
        log.Info("Your data has been successfully saved");
    }
private void w_Click_1(object sender, EventArgs e)
    {
        int x = 0;
        try
        {
            int y = 1 / x;
        }
        catch(Exception ex)
        {
            log.Error(ex.Message, ex);
        }
    }

我想看到的是我的数据库中有日志,并且我也确实创建了一个文件,其中包含上面的值,所以我想知道代码中的问题在哪里

0 个答案:

没有答案