我的Windows服务为什么不将其写入日志文件? [英] Why won't my windows service write to my log file?

查看:249
本文介绍了我的Windows服务为什么不将其写入日志文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Windows服务,并使用nlog进行日志记录.当我从Visual Studio ide运行时,一切正常.日志文件更新没有问题.当我安装该服务时,该服务运行良好,但日志文件从未更新.如果有帮助,我正在本地服务下运行.是的,我已经在我的应用程序文件夹下创建了logs目录.

I have a windows service and use nlog for logging. Everything works fine when I run from the visual studio ide. The log file updates with no issues. When I install the service, the service runs fine but the log file never updates. I am running under LOCAL SERVICE if that helps. Yes, I have created the logs directory under my application folder.

 <?xml version="1.0" encoding="utf-8" ?>
 <nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >

  <targets>
    <target name="file" xsi:type="File" fileName="${basedir}/logs/${shortdate}_info.txt"
            layout="${date} ${logger} ${message}" />
  </targets>

  <rules>
    <logger name="*" minlevel="Info" maxlevel="Info" writeTo="file" />
  </rules>
</nlog>

推荐答案

您的本地服务帐户无权写入指定的文件位置.您可以在服务属性对话框的登录"选项卡中将其设置为使用系统帐户,也可以在设置过程中设置用户帐户.

Your local service account doesn't have access to write to the file location specified. You set it to use a system account in the "Log On" tab of the service properties dialog, or you can set up the user account as part of the setup process.

这篇关于我的Windows服务为什么不将其写入日志文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆