![](/img/trans.png)
[英]Is there a to turn on/off the logging functionality in .net core specially the serilog(logging data into .txt file)
[英]Failed to write loggind data in file using Serilog .Net Logging
我是新的 Serail 日志,我已经为日志文件创建了这个配置
var log = new LoggerConfiguration().WriteTo.File(Application.dataPath + "/AppLogs.txt",rollingInterval:RollingInterval.Day).CreateLogger();
并用它来记录细节(我希望它也应该写在上面提到的日志文件中)
Log.Information("Test Log info ");
Log.Error("Test Log Error");
但是文件创建成功,没有日志。 我错过了什么。 我想使用 serail 日志在文件中记录数据。
为了使用 static 功能
Log.Information("Test Log info ");
Log.Error("Test Log Error");
我必须在配置后设置全局静态可访问记录器
Log.Logger = log;
所以我的最终配置代码是
var log = new LoggerConfiguration().WriteTo.File(Application.dataPath + "/AppLogs.txt",rollingInterval:RollingInterval.Day).CreateLogger();
Log.Logger = log ;//setting global logger
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.