简体   繁体   English

ASP.Net Classic Serilog 不写入文件

[英]ASP.Net Classic Serilog not writing to file

I am trying to create an ilogger with unity and I have it created fine but when I invoke the logger, nothing is written to the file.我正在尝试创建一个统一的 ilogger 并且我已经创建好了,但是当我调用记录器时,没有任何内容写入文件。 What am I missing?我错过了什么?

This is my unity这是我的团结

container.RegisterType<ILogger>(new ContainerControlledLifetimeManager(), new InjectionFactory((ctr, type, name) => {

ILogger log = new LoggerConfiguration()
.Enrich.FromLogContext()
.Enrich.WithThreadId()
.Enrich.WIthProperty("ApplicationVersion", GetApplicationVersion())
.WriteTo
  .Logger(lc => lc.Filter
                .ByIncludingOnly(e => e.Level == LogEventLevel.Information || e.Level == LogEventLevel.Debug)
.WriteTo.RollingFile(Path.Combine(path, @"\infolog -{ Date}.txt")))
.CreateLogger();

return log;
}));

Then in my controller I inject it然后在我的控制器中注入它

MyClass(ILogger ilog){
_ilog = ilog;
}

public void DoSomething(){
this._ilog.Information("logged message");
}

I expect to see a log file in the directory called Errorlogs/info-07032021.txt but nothing is there.我希望在名为 Errorlogs/info-07032021.txt 的目录中看到一个日志文件,但那里什么也没有。 What am I missing?我错过了什么?

Found it.找到了。 Path combine only worked when the second argument wasn't an absolute path.路径组合仅在第二个参数不是绝对路径时才有效。 So I had to remove the "@"所以我不得不删除“@”

I had to make it我必须做到

   .WriteTo.RollingFile(path + "\infolog -{ Date}.txt")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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