Log4Net登录MySql不写

时间:2012-09-21 14:22:38

标签: c# mysql log4net

我尝试登录MySql表但不会写。 它没有显示任何错误,也没有在mysql表中写任何内容。

这是log4net的web.config设置:

<log4net>

    <appender name="MySql_ADONetAppender" type="log4net.Appender.ADONetAppender">
      <bufferSize value="100" />
      <connectionType value="MySql.Data.MySqlClient.MySqlConnection, MySql.Data"/>
      <connectionString value="Server=127.0.0.1;Database=svil;Uid=LogUser;Pwd=LogPass;"/>
      <commandText value="INSERT INTO Log (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="%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="4000"/>
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%message"/>
        </layout>
      </parameter>
      <parameter>
        <parameterName value="?exception"/>
        <dbType value="String"/>
        <size value="2000"/>
        <layout type="log4net.Layout.ExceptionLayout"/>
      </parameter>
    </appender>

    <root>
      <level value="ALL"/>
      <appender-ref ref="MySql_ADONetAppender"/>
    </root>
</log4net>

在global.asax中:

protected void Application_Start(object sender, EventArgs e)
{
    log4net.Config.XmlConfigurator.Configure();
}

这是aspx页面中的一个简单日志:

public partial class _Default : System.Web.UI.Page
{
    private static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

    protected void Page_Load(object sender, EventArgs e)
    {
        log.Info("Test Log Message");
    }
}

1 个答案:

答案 0 :(得分:6)

你的bufferSize值=“100”表示在记录100条消息之前没有任何内容写入日志表,将其更改为1

还要检查此http://weblogs.asp.net/drnetjes/archive/2005/02/16/374780.aspx