【发布时间】:2017-11-20 10:04:55
【问题描述】:
我使用 NLog,并为我的应用程序创建了自己的日志提供程序。我在 StartUp 类中使用 NLog 设置了配置。
我将向您展示 Program.cs 现在的样子。
public static void Main(string[] args)
{
var configurationDic = CreateConfigurationDictionary();
// In here it can throw an exception therefore I need to be able to log here
var webHost = BuildWebHost(configurationDic, args);
var applicationLogger = webHost.Services.GetService<IMyTestLogProvider>().ApplicationLogger;
applicationLogger.LogInformation("*************** Start up ***************");
webHost.Run();
}
除了我需要在主类中更早地登录之外,日志记录工作正常。在构建网络主机之前如何获取应用程序记录器的任何想法?
我已经看到了示例 https://github.com/NLog/NLog.Web/wiki/Getting-started-with-ASP.NET-Core-2 ,我应该能够做到:
var logger = NLogBuilder.ConfigureNLog("NLog.config").GetCurrentClassLogger();
但我的应用程序不知道 NLogBuilder 是什么,尽管我已经安装了 NLog nuget 包。
有什么想法吗?
最好的问候 抢
【问题讨论】:
-
您究竟在做什么在需要记录的网络主机并且不能延迟到主机实际初始化时?如果那里发生了很多事情,这可能表明您的 web 应用程序做的太多而与 web 应用程序无关。跨度>
-
通知nuget.org/packages/NLog.Web.AspNetCore/4.5.0-rc1已经发布。它应该为 net461 启用 NLogBuilder。
标签: c# asp.net asp.net-mvc asp.net-core nlog