简体   繁体   中英

Failed to write loggind data in file using Serilog .Net Logging

I am new Serail log, I have created this configuration for log file

var log = new LoggerConfiguration().WriteTo.File(Application.dataPath + "/AppLogs.txt",rollingInterval:RollingInterval.Day).CreateLogger();

And using this to log details (I hope that it should also be written in log file mentioned above)

Log.Information("Test Log info ");
Log.Error("Test Log Error");

But the file created successfully with no log. Which thing i am missing. I want to log data in the file using serail log.

In order to use static functions

Log.Information("Test Log info ");
Log.Error("Test Log Error");

I have to set global statically accessible logger after the configuration

Log.Logger = log;

So my final Config code is

var log = new LoggerConfiguration().WriteTo.File(Application.dataPath + "/AppLogs.txt",rollingInterval:RollingInterval.Day).CreateLogger();
Log.Logger = log ;//setting global logger

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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