登录服务问题 [英] problem of log in service

查看:71
本文介绍了登录服务问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序已安装为Windows服务.
对于登录文件,我使用以下类:

My application is installed as windows service.
For log on file, I use the following class :

debugTextListener = gcnew TextWriterTraceListener("c:\\myApp.log.txt");
...
debugTextListener->WriteLine( "app starts.");
debugTextListener->Flush();


如果我将我的应用程序用作程序,则日志文件已正确填充;
如果我将其用作服务,它将正常运行,但不会创建日志文件.
有任何想法吗?
最好的问候.


If I use my application as program, log file is filled correctly;
If I use it as service, It run correctly, but no log file is created.
Any Idea ?
Best regards.

推荐答案

这取决于Windows服务在哪个凭据下运行. Windows服务正在运行的帐户可能没有足够的权限写入C:的根文件夹.如果可能,请以程序身份运行该服务时尝试让该服务在同一帐户下运行,并查看是否有助于解决该问题.然后由您决定是更改C:\上的ACL,还是让服务在具有足够写入C:\权限的帐户下运行.

问候,

Manfred
It depends under which credentials the windows service is running. It may well be that the account the windows service is running under does not have sufficient rights to write to the root folder of C:. If possible try to let the service run under the same account when you ran it as a program and see if that will help fix the issue. Then it is up to you to decide to either change the ACL on C:\ or have the service run under an account that has sufficient rights to write to C:\.

Regards,

Manfred


正如Manfred解释的那样,服务器通常无权写入此位置.这样的位置完全是非法的;您应该在用户"或文档和设置"下使用适当的目录.同样,在任何情况下都不会使用任何硬编码的路径名.所有路径名始终在运行时根据程序集位置(仅适用于只读文件),配置文件的环境进行计算.

但是您甚至不需要这样做.要进行日志记录,请通过类 System.Diagnostics.EventLog http://msdn使用系统日志. microsoft.com/en-us/library/system.diagnostics.eventlog.aspx [如何在文件夹下创建事件日志 [ ^ ],
将MsBuild OutPut即时发送到TextBox Windows应用程序中 [ ^ ].

这样,您可以根据项目使日志结构化,重定向日志等.

—SA
As Manfred explained, the server usually don''t have permission to write to this location. The locations like that are simply illegal; you should use appropriate directory under "Users" or "Documents and Settings". Also, there are no cases when any hard-coded path name could be useful, ever. All path names are always calculated during run-time, based on assembly location (for read-only files only), environment of configuration files.

But you don''t need to do even that. For logging, use the system log via the class System.Diagnostics.EventLog, http://msdn.microsoft.com/en-us/library/system.diagnostics.eventlog.aspx[^].

For some more useful detail and idea, please see my past solutions:
How to create event log under a folder[^],
MsBuild OutPut to the TextBox on the fly in Windows Application[^].

This way, you can make logging structured per you project, redirect it, etc.

—SA




这意味着该服务没有足够的权限来
创建日志文件.尝试为服务授予管理员权限.
请尝试以下方法之一.

1.编辑清单以确保该服务仅在具有管理员权限的情况下运行.
< requestedExecutionLevel
level ="asInvoker | highestAvailable | requireAdministrator"
uiAccess ="true | false"/>
2.查找当前特权,然后对其进行调整以赋予管理员特权.
LookupPrivilegeValue()和AdjustTokenPrivileges()将解决问题.


谢谢
Hi,

This means that the service doesn''t have sufficient privileges to
create the log file. Try giving admin privilege to service.
Try one of the following.

1. Edit the manifest to make sure that the service will run only with admin privileges.
<requestedExecutionLevel
level="asInvoker|highestAvailable|requireAdministrator"
uiAccess="true|false"/>
2. Lookup the current privilege, and then adjust it to give admin privileges.
LookupPrivilegeValue() and AdjustTokenPrivileges() will do the trick.


Thanks


这篇关于登录服务问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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