开发者

.NET 4, writing a windows service for logging and directory monitoring

开发者 https://www.devze.com 2023-02-23 05:53 出处:网络
I\'ve written a software as a windows console application; there\'s a config file that specifies how to log in thesection.

I've written a software as a windows console application; there's a config file that specifies how to log in the section.

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:

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?

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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号