首页新闻找找看学习计划

log4net如何根据不同级别输出到不同地方

0
悬赏园豆:5 [已解决问题] 解决于 2008-05-30 10:40
<P>今天要用log4net记录用户操作。<BR>遇到了如题的问题。我想用log4net把级别为Info的信息保存到oracle数据库,其它的都保存到文件<BR>请教配置文件该如何写</P> <P>试了很久了,还是没有保存到数据库&nbsp; 下面是我的配置,<BR>&lt;log4net&gt;<BR>&nbsp; &lt;root&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;level value="INFO" /&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;appender-ref ref="AdoNetAppender_Oracle" /&gt;<BR>&nbsp; &lt;/root&gt;<BR>&nbsp; &lt;!--&lt;root&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;level value="ERROR"/&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;appender-ref ref="RollingFileAppender"/&gt;<BR>&nbsp; &lt;/root&gt;--&gt;&nbsp; <BR>&nbsp; &lt;appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender"&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;file value="log\\log2.txt"/&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;appendToFile value="true"/&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;maxSizeRollBackups value="10"/&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;maximumFileSize value="2000KB"/&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;rollingStyle value="Size"/&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;staticLogFileName value="true"/&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;lockingModel type="log4net.Appender.FileAppender+MinimalLock"/&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;layout type="log4net.Layout.PatternLayout"&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline"/&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;/layout&gt;<BR>&nbsp; &lt;/appender&gt;</P> <P>&nbsp; &lt;appender name="AdoNetAppender_Oracle" type="log4net.Appender.AdoNetAppender"&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;connectionType value="System.Data.OracleClient.OracleConnection, System.Data,&nbsp; Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" /&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;connectionString value="Password=111;User ID=111;Data Source=tempo" /&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;bufferSize value="128" /&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;commandText value="INSERT INTO Log(msg) VALUES (:msg)" /&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;parameter&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;parameterName value=":msg" /&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;dbType value="String" /&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;size value="2000" /&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;layout type="log4net.Layout.PatternLayout"&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;conversionPattern value="%message" /&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/layout&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;/parameter&gt;<BR>&nbsp; &lt;/appender&gt;<BR>&lt;/log4net&gt;</P>
readonly的主页 readonly | 菜鸟二级 | 园豆:406
提问于:2008-05-24 18:41
< >
分享
最佳答案
0
看看这个有没有帮助? http://www.cnblogs.com/anderslly/archive/2007/03/09/log4netconfigsamples.html
Anders Cui | 小虾三级 |园豆:1570 | 2008-05-24 19:03
其他回答(1)
0
不同级别的好像不可以,只能不同的 logger name 设置不同的输出
一滴水 | 园豆:210 (菜鸟二级) | 2008-05-24 23:01
不同的 logger name 设置不同的输出 ? 如何做到的?
支持(0) 反对(0) 高天蒲 | 园豆:35 (初学一级) | 2010-05-05 14:44
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册