【发布时间】:2021-09-15 08:19:12
【问题描述】:
我正在尝试创建一个具有统一性的 ilogger,并且它创建得很好,但是当我调用记录器时,没有任何内容写入文件。 我错过了什么?
这是我的团结
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;
}));
然后在我的控制器中注入它
MyClass(ILogger ilog){
_ilog = ilog;
}
public void DoSomething(){
this._ilog.Information("logged message");
}
我希望在名为 Errorlogs/info-07032021.txt 的目录中看到一个日志文件 但什么都没有。我错过了什么?
【问题讨论】:
-
{和Date}之间应该有空格吗?
标签: c# asp.net logging log4net serilog