在Azure中使用事件日志(在事件查看器中写入)

hey*_*you 5 c# asp.net azure event-log event-viewer

我的网站用ASP.NET编写,我使用EventLog将日志写入事件查看器.它已在生产中运行(操作系统:Windows Server 2012 R2),并且在记录某些错误时没有遇到任何问题.我现在计划将服务器迁移到Azure - App Services.我想知道我的代码在记录错误后是否仍然可以移动到Azure - App Services?如果是,那么我如何查看我的网站记录的错误?我无法在Azure - App Services中看到事件查看器.如果不是那么在记录错误时替换我的代码的最简单和最快的替代方法是什么?

这是我的代码:

public static void LogEventLog(string message, EventLogEntryType logType)
    {
        string source = AppConfig.ErrorEventViewerSource;

        // Since we can't prevent the app from terminating, log this to the event log. 
        CreateEventSource(source);

        // Create an EventLog instance and assign its source.
        EventLog myLog = new EventLog();
        myLog.Source = source;
        myLog.WriteEntry(message, logType);

    }



    public static void CreateEventSource(string source)
    {
        if (!EventLog.SourceExists(source))
        {
            EventLog.CreateEventSource(source, "Application");
        }
    }
Run Code Online (Sandbox Code Playgroud)

sir*_*ank 4

我认为正确的解决方案是使用此处描述的方法之一将您的应用程序连接到应用程序见解。从短期来看,为了让我的工作正常工作,我必须删除对CreateEventSource()现有日志的调用并写入现有日志,因为我的应用程序无权在应用程序服务主机上创建新日志。