Serilog

61 views
Skip to first unread message

Aleš Vojáček

unread,
May 31, 2021, 8:21:50 AM5/31/21
to topshelf-discuss
Hi,
is there some way how to use structured logs with TopSelf (I'm using serilog).
If I start application it logs ok, but when I start app as service. There are only messages from topshelf not from my service.
I found some examples like this:
public class VZPService
{
readonly Timer _timer;
private static readonly LogWriter Log = HostLogger.Get<VZPService>();
public VZPService()
{
_timer = new Timer(1000) {AutoReset = true};
_timer.Elapsed += (sender, eventArgs) => Log.InfoFormat("It is {Time} and all is well", DateTime.Now);
}
.....

But this Log.Info, Log.InfoFormat does not create structured logs it only logs string messages.

The only solution is create Serilog logger inside my class to use it?

Thank you Ales.

Aleš Vojáček

unread,
May 31, 2021, 9:02:22 AM5/31/21
to topshelf-discuss
Hi all,
I found that I can use global Log.Info from serilog and it is working (not only when it's running from console mode but when it is started as service) I have to use absolute path to log file .

If there is another way to use structured logs instead of global Log, please let me know.

Thank you Ales

Dne pondělí 31. května 2021 v 14:21:50 UTC+2 uživatel Aleš Vojáček napsal:
Reply all
Reply to author
Forward
0 new messages