简体   繁体   English

从Windows服务登录到另一台计算机

[英]Logging from a Windows Service to another machine

I wrote one windows service locally..Now i will going to deploy it on server...My requirement is that i want to write start & stop timing of service on my local machine. 我在本地编写了一个Windows服务..现在我将要在服务器上部署它...我的要求是我想在本地计算机上编写服务的启动和停止时间。 so i did that locally when my service is on my local machine.. But when it will get deployed on server so how will i write that start & end time to that text file which is on my local machine...? 所以当我的服务在我的本地机器上时,我是在本地完成的。但是当它部署在服务器上时,我如何将开始时间和结束时间写入到我的本地机器上的文本文件中?

If I'm correct in interpreting your question, then you're deploying the service to MachineA and your PC is MachineB . 如果我对您的问题的解释是正确的,则说明您正在将该服务部署到MachineA,而您的PC是MachineB You want to have the service running on MachineA write to a log file on MachineB? 您是否要在MachineA上运行的服务写入MachineB上的日志文件?

If this is the case, it's a simple matter to create a share on MachineB and have the service write to a file on that share, rather than a local file. 在这种情况下,只需在MachineB上创建共享并将服务写入该共享上的文件(而不是本地文件)即可。 So, rather than writing to C:\\Log\\MyLogFile.log , have the service write to \\\\MachineB\\Log\\MyLogFile.log . 因此,让服务写入\\\\MachineB\\Log\\MyLogFile.log C:\\Log\\MyLogFile.log ,而不是写入C:\\Log\\MyLogFile.log \\\\MachineB\\Log\\MyLogFile.log

One thing to consider is the fact that this means that your service won't be able to log unless your PC is running. 要考虑的一件事是,这意味着除非您的PC正在运行,否则您的服务将无法登录。 You'll need to ensure that your code fails gracefully if this occurs, rather than hanging or crashing. 如果发生这种情况,您需要确保代码正常失败,而不是挂起或崩溃。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM