windows-service-rs icon indicating copy to clipboard operation
windows-service-rs copied to clipboard

Not able to perform logging inside created service

Open SSinghLenek opened this issue 10 months ago • 3 comments

I am trying to create a service with logging, but logging is working correctly when we run the exe file. But not logging any thing when service is running.

Also service is crashing if logging is done outside closures.

I am using log4rs for logging.

SSinghLenek avatar Apr 19 '24 11:04 SSinghLenek

Are you initializing the logger in the service process? In the example in the main readme that would be my_service_main, not main. Please provide minimal code to reproduce to increase the chance someone can help you.

faern avatar Apr 19 '24 16:04 faern

Thanks you @faern. I was initializing the logger in main. I will try this and update here about the progress.

SSinghLenek avatar Apr 19 '24 18:04 SSinghLenek

Running as a windows service, program's default working dir is c:\windows\systemd32 where the log file should be. We can change the default setting like this:

    let exe = std::env::current_exe().unwrap();
    let dir = exe.parent().unwrap();
    std::env::set_current_dir(dir).unwrap();

Hope this helps.

wentaotoyou avatar Aug 04 '24 15:08 wentaotoyou