股票新手入门指南:log4net 使用说明sd
来源:百度文库 编辑:九乡新闻网 时间:2024/10/06 02:01:41
1 拷贝 log4net.dll 到源代码根目录
2 在项目中添加对log4net.dll 的引用
3 修改程序配置文件 添加两部分内容:
(1) 在
(2) 在
说明:上面的配置里的update.log是要记录到的文件名 其他参数的意义请参考手册
4 在程序启动时读取log4net的配置文件
如果是cs程序 在根目录的Program.cs中 在mani方法中添加
log4net.Config.XmlConfigurator.Configure();
如果是bs程序 在根目录的Global.asax.cs 中的Application_Start方法中添加
log4net.Config.XmlConfigurator.Configure();
5 然后 可在在程序中使用log4net功能了 使用方法如下:
log4net.ILog log = log4net.LogManager.GetLogger("AppLogger"); //获取一个日志记录器
log.Info(DateTime.Now.ToString() + ": login success"); //写入一条新log