首页 新闻 会员 周边 捐助

log4net 不能写进slqserver,请大家帮忙看一下

0
悬赏园豆:20 [已关闭问题] 关闭于 2010-04-26 00:20

能写到文件里去,就是不能写到数据库里去,请大家帮忙看一下是怎么回事

Global.asax

void Application_Start(object sender, EventArgs e)
    {
        // Code that runs on application startup
        log4net.Config.XmlConfigurator.Configure();
    }

测试代码

protected void Button2_Click(object sender, EventArgs e)
    {
        ILog log = LogManager.GetLogger("AdoNetAppender");
        log.Warn("xiaoliepower");
        log.Warn("xiaoliepower");
        log.Warn("xiaoliepower");
        log.Warn("xiaoliepower");
        log.Warn("xiaoliepower");
    }

web.config

<configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"/>
  </configSections>
  <log4net>
    <root>
      <level value="All" />
      <appender-ref ref="RollingFileAppender"/>
      <appender-ref ref="AdoNetAppender"/>
    </root>
    <appender name="AdoNetAppender" type="log4net.appender.adonetappender">
      <buffersize value="1" />
      <connectiontype value="system.data.sqlclient.sqlconnection, system.data, version=1.0.3300.0, culture=neutral, publickeytoken=b77a5c561934e089" />
      <connectionstring value="server=localhost;database=xiaolie;uid=sa;pwd=xiaolie;" />
      <commandtext value="insert into log4net ([message],[datetime],[runtime],[threadid],[priority],[class],[linenumber],[filename])
                                       values (@message, @datetime, @runtime, @threadid, @priority, @class,@linenumber,@filename)" />
      <parameter>
        <parametername value="@message" />
        <dbtype value="string" />
        <size value="1000" />
        <layout type="log4net.layout.patternlayout">
          <conversionpattern value="%message" />
        </layout>
      </parameter>
      <parameter>
        <parametername value="@datetime" />
        <dbtype value="datetime" />
        <layout type="log4net.layout.rawtimestamplayout">
          <conversionpattern value="%d" />
        </layout>
      </parameter>
      <parameter>
        <parametername value="@runtime" />
        <dbtype value="string" />
        <size value="200" />
        <layout type="log4net.layout.patternlayout">
          <conversionpattern value="%r" />
        </layout>
      </parameter>
      <parameter>
        <parametername value="@threadid" />
        <dbtype value="string" />
        <size value="200" />
        <layout type="log4net.layout.patternlayout">
          <conversionpattern value="%t" />
        </layout>
      </parameter>
      <parameter>
        <parametername value="@priority" />
        <dbtype value="string" />
        <size value="2000" />
        <layout type="log4net.layout.patternlayout">
          <conversionpattern value="%p" />
        </layout>
      </parameter>
      <parameter>
        <parametername value="@class" />
        <dbtype value="string" />
        <size value="2000" />
        <layout type="log4net.layout.patternlayout" >
          <conversionpattern value="%c" />
        </layout>
      </parameter>
      <parameter>
        <parametername value="@linenumber" />
        <dbtype value="string" />
        <size value="2000" />
        <layout type="log4net.layout.patternlayout" >
          <conversionpattern value="%l" />
        </layout>
      </parameter>
      <parameter>
        <parametername value="@filename" />
        <dbtype value="string" />
        <size value="2000" />
        <layout type="log4net.layout.patternlayout" >
          <conversionpattern value="%f" />
        </layout>
      </parameter>
    </appender>
    <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender" >
      <file value="testlog.txt" />
      <appendToFile value="true" />
      <maxSizeRollBackups value="10" />
      <maximumFileSize value="100" />
      <rollingStyle value="Date" />
      <datePattern value="yyyy-MM-dd"/>
      <staticLogFileName value="true" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%-5level %date %logger - %message%newline" />
      </layout>
    </appender>
    <root>
      <level value="ALL"/>
      <appender-ref ref="AdoNetAppender"/>
    </root>
    <logger name="AdoNetAppender">
      <level value="All"/>
      <appender-ref ref="AdoNetAppender"/>
      <appender-ref ref="RollingFileAppender"></appender-ref>
    </logger>
  </log4net>

xiaoliepower的主页 xiaoliepower | 初学一级 | 园豆:13
提问于:2010-04-19 16:56
< >
分享
所有回答(1)
0

看你引用log4net.dll的版本,要跟version=1.0.3300.0, 这个一致。我也是研究了一天。

20121221 | 园豆:201 (菜鸟二级) | 2013-09-05 11:08
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册