Asp.net 核心 502.5 - 部署时出现进程故障错误 - 日志记录问题



我需要一些帮助,让我的 asp.net 核心 mvc 版本 2.1 站点上的日志记录工作。 我已经能够让站点成功地将错误写入事件日志,但只能写入应用程序/应用程序事件日志/源。 我希望将源设置为"我的网站",以便我可以轻松过滤日志。

这是我的程序.cs代码,它在部署时产生 502.5 错误:

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.ConfigureLogging((hostingContext, logging) =>
{
logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
var eventLogSettings = new EventLogSettings();
eventLogSettings.SourceName = "MySite";
logging.AddEventLog(eventLogSettings);
logging.AddConsole();
logging.AddDebug();
logging.AddEventSourceLogger();
})
.UseIISIntegration()
.UseStartup<Startup>();

当我部署站点并转到/home/index 页时,我收到 502.5 错误,并看到事件查看器中记录了以下错误:

应用:网络.exe 核心CLR 版本:4.6.27019.6 说明:由于未处理的异常,进程已终止。 异常信息:系统.聚合异常:写入记录器时出错。(找不到源,但无法搜索部分或全部事件日志。 若要创建源,需要具有读取所有事件日志的权限,以确保新的源名称是唯一的。 无法访问的日志:安全性。---> System.Security.SecurityException:找不到源,但无法搜索部分或全部事件日志。 若要创建源,需要具有读取所有事件日志的权限,以确保新的源名称是唯一的。 无法访问的日志:安全性。 at System.Diagnostics.EventLog.FindSourceRegistration(String source, String machineName, Boolean readOnly, Boolean wantToCreate( at System.Diagnostics.EventLog.SourceExists(String source, String machineName, Boolean wantToCreate(

我错过了什么?

好吧,它就在例外中,当它。 CoreCLR 在尝试验证源时被轰炸,而源在服务器上不存在。 我通过以管理员身份在 powershell 中运行以下命令来创建源代码: [System.Diagnostics.EventLog]::CreateEventSource("MySite", "Application"(

之后,该网站运行良好,其中的错误具有源"我的网站"。

最新更新