我正在使用Serilog.Extensions.Logging.File登錄文件。這是我的appsettings.json文件: "Logging": { "IncludeScopes": false, "LogLevel": { "Default": "Information", "System": "None", "Microsoft": "None" } }, "LoggingFile": { "IncludeScopes": false, "pathFormat": "C:/logs/APILogs-{Date}.log", "LogLevel": { "Default": "Trace", "System": "None", "Microsoft": "None" } }我的 Startup.cs 代碼:public void Configure( IApplicationBuilder app, IHostingEnvironment env, IApiVersionDescriptionProvider provider, ILoggerFactory loggerFactory) { // Removed other codes loggerFactory.AddFile(Configuration.GetSection("LoggingFile")); }但它仍然記錄 mvc 請(qǐng)求信息,如下所示:(ca22a1cb)http://localhost:53534/api/values2019-09-21T13:28:59.8309629+05:30 80000019-0004-ff00-b63f-84710c7967bb [INF] 請(qǐng)求在 202.16ms 200 內(nèi)完成 (791a596a)(ca22a1cb)http://localhost:53534/favicon.ico2019-09-21T13:29:00.2020227+05:30 8000001a-0004-ff00-b63f-84710c7967bb [INF] 請(qǐng)求在 73.5631ms 200 內(nèi)完成 (791a596a)我不記錄這些。它應(yīng)該只在我想記錄時(shí)記錄,例如在我的控制器中_logger.LogInformation("Hello Info");
_logger.LogError("Hello error");
1 回答

一只名叫tom的貓
TA貢獻(xiàn)1906條經(jīng)驗(yàn) 獲得超3個(gè)贊
將以下代碼行添加到啟動(dòng)的構(gòu)造函數(shù)中
Log.Logger?=?new?LoggerConfiguration() ????????????.MinimumLevel.Debug() ????????????.MinimumLevel.Override("Microsoft",?LogEventLevel.Error) ????????????.MinimumLevel.Override("System",?LogEventLevel.Error) ????????????.Enrich.FromLogContext() ????????????.WriteTo.RollingFile("C:/logs/APILogs-{Date}.log") ????????????.CreateLogger();
然后在配置方法中,添加以下行。
loggerFactory.AddSerilog();
- 1 回答
- 0 關(guān)注
- 228 瀏覽
添加回答
舉報(bào)
0/150
提交
取消