如何在我的项目中使用Log4Net [英] How to use Log4Net in my Project
本文介绍了如何在我的项目中使用Log4Net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
尊敬的会员,
我在此站点上发布了许多问题,并感谢您为该站点的所有成员解决了我的问题.
我有新问题
log4net教程 [
Dear Member,
I post many question on this site and thank for solve my problem to all member of this site.
i have new problem
log4net Tutorial[^]
in this i want to generate log message par day wise and there is a new line gap between ever message and over all information of how to configer it for my requirement.
Thank you
推荐答案
首先将以下2个库添加到您的项目中
使用log4net.Appender;
使用log4net.Config;
然后在页面加载之前添加此行
公共静态只读log4net.ILog日志= LogManager.GetLogger(typeof(Your_Page_class_Name));
最后输入
XmlConfigurator.Configure();
在页面加载中.
还有一点不要错过您的webconfig文件中的以下行
First of all add the following 2 libraries to your project
using log4net.Appender;
using log4net.Config;
and then add this line before page load
public static readonly log4net.ILog log = LogManager.GetLogger(typeof(Your_Page_class_Name));
and lastly type
XmlConfigurator.Configure();
in page load.
One thing more dont miss to the the following lines in your webconfig file
<log4net>
<root>
<level value="DEBUG" />
<appender-ref ref="RollingFileAppender" />
</root>
<logger name="AKPOS_MagStripe_Interface">
<level value="DEBUG" />
<appender-ref ref="MagstripeAppender" />
</logger>
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="EMISLog.log" />
<appendToFile value="true" />
<lockingModel type="log4net.Appender.FileAppender+ExclusiveLock " />
<rollingStyle value="Date" />
<datePattern value=".yyyyMMdd_bak" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %level %logger - %message%newline" />
</layout>
</appender>
</log4net>
这篇关于如何在我的项目中使用Log4Net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文