首页 > Web开发 > 详细

log4net服务启动后没有记录日志

时间:2019-08-09 13:35:32      阅读:120      评论:0      收藏:0      [点我收藏+]

有时候在用log4net的时候,调试或执行是ok的,但是安装服务后没有记录日志。

这是因为服务启动是在C盘启动,而程序放的位置在别的目录。

这时候需要指定读取配置文件的位置为程序所在的目录

string execuFilePath = Assembly.GetExecutingAssembly().Location;
string execuDirPath = Path.GetDirectoryName(execuFilePath);
string log4netconfigFilePath = execuDirPath + "\\log4net.config";

//初始化log4net配置的信息
XmlConfigurator.ConfigureAndWatch(log4net.LogManager.GetRepository(Assembly.GetExecutingAssembly()), new FileInfo(log4netconfigFilePath));

//初始化logger
ILog logger = LogManager.GetLogger(typeof(ServerJobRunning));

 

之后就可以正常使用了。

log4net服务启动后没有记录日志

原文:https://www.cnblogs.com/king123/p/11326398.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!