在日志文件中写入的 Windows 服务权限 [英] Windows service rights to write in log file

查看:124
本文介绍了在日志文件中写入的 Windows 服务权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 C# 创建了一个 Windows 服务,该服务在 C:\ 中写入日志(使用 NLog)程序数据.
当我调试服务(在我的 Windows 7 上)(使用上面编写的代码)时,正确创建了日志文件并正确写入了日志记录.但是当我在运行于 Windows server 2008 (x86) 的服务器上安装该服务时,没有创建日志文件(我还检查了 C:\Windows\System32\,什么都没有).

I have created a Windows service using C# that writes logs (with NLog) in C:\ProgramData.
When I debug the service (on my Windows 7) (using the code written above), the log file is correctly created and log records correctly written. But when I install the service on my server which runs on Windows server 2008 (x86), no log file is created (I have also checked in C:\Windows\System32\, nothing there).

我怀疑是授权问题,如何知道我的服务使用了哪些权限?

I suspect that it is an authorization problem so how can I know what rights is my service using?

PS: 我已经使用命令行安装了我的服务 C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe C:\PathToMyService\MyService.exe 具有管理员权限.

PS: I have installed my service using the command line C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe C:\PathToMyService\MyService.exe with Administrator rights.

推荐答案

运行 services.msc,找到您的服务,右键单击并选择 Properties.检查 Log On 标签以查看您的服务在哪个帐户下运行.

Run services.msc, find your service right click and select Properties. Check the Log On tab to see which account your service is running under.

至于您的问题,默认情况下,我认为大多数服务在 Local System Account 下运行,我认为该帐户具有写入 C:\ProgramData 目录的权限.您确定 nlog.config 文件与您的服务一起部署了吗?

As for your problem, by default I think most services run under the Local System Account which I would assume has permissions to write to the C:\ProgramData directory. Have you made sure the nlog.config file is deployed with your service?

这篇关于在日志文件中写入的 Windows 服务权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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