windows-service-rs
windows-service-rs copied to clipboard
Not able to perform logging inside created service
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.
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.
Thanks you @faern. I was initializing the logger in main. I will try this and update here about the progress.
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.