I've written a software as a windows console application; there's a config file that specifies how to log in the section.
我已经编写了一个软件作为windows控制台应用程序;有一个配置文件指定如何在该部分中进行日志记录。
Now that I've tested it and it works fine, I want to convert it into a windows service. I created a new project but I have two problems:
现在我已经测试了它,它运行良好,我想将它转换为windows服务。我创建了一个新项目,但我有两个问题:
1) Logging doesn't seem to happen anymore; the config file is no more read, or logging can't happen for some other reason (permissions?). Anyway I was thinking what is the best way to log for a windows service, maybe through the windows event logging? And how? Or is it better to make my config file work so that I can disable logging without recompiling?
1)日志似乎不再发生;配置文件不再读取,或者由于其他原因(权限?)不能进行日志记录。不管怎样,我在想什么是最好的登录windows服务的方法,也许是通过windows事件日志记录?以及如何?还是让我的配置文件工作更好,这样我就可以在不重新编译的情况下禁用日志记录?
2) In the service I use a set of FileSystemWatcher objects to monitor directories. It looks like in the service I don't get the monitoring events anymore. Any hints?
在服务中,我使用一组文件系统监视对象来监视目录。看起来在服务中我再也没有监控事件了。有提示吗?
Thanks
谢谢
edit: A step forward for point 2) - After debugging I've found that I get the events, the problem is that in the event I try to move a file with File.Move
and it fails.
在调试之后,我发现我得到了事件,问题是,在事件中,我试图将文件移动到文件中。移动和它失败。
edit2: Another little step forward for point 2) - I had to install the service with user permissions, otherwise it doens't let me move a file. This is solved.
edit2:对于第2点的另一个小步骤,我必须安装用户权限的服务,否则它不会让我移动文件。这是解决。
1 个解决方案
#1
1
There is more than one question in your post.
你的帖子里有不止一个问题。
One possible reason why you don't see logs you might be looking at the wrong place. Services are started with Current Working Directory as %systemroot%\system32, so it will try to create logs there.
你没有看到日志的一个可能的原因是你可能看错了地方。服务从当前的工作目录开始,作为%systemroot%\system32,因此它将尝试在那里创建日志。
#1
1
There is more than one question in your post.
你的帖子里有不止一个问题。
One possible reason why you don't see logs you might be looking at the wrong place. Services are started with Current Working Directory as %systemroot%\system32, so it will try to create logs there.
你没有看到日志的一个可能的原因是你可能看错了地方。服务从当前的工作目录开始,作为%systemroot%\system32,因此它将尝试在那里创建日志。