我的网站是用 ASP.NET 编写的,我使用 EventLog 将日志写入事件查看器。它已经在生产环境中运行(操作系统:Windows Server 2012 R2),并且在记录一些错误时没有遇到任何问题。我现在计划将服务器迁移到 Azure - 应用服务。我想知道我的记录错误的代码在迁移到 Azure - 应用服务后是否仍然有效?如果是,那么我如何查看我的网站记录的错误?我在 Azure - 应用服务中看不到事件查看器。如果不是,那么在记录错误时替换我的代码的最简单、最快的替代方法是什么??
这是我的代码:
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");
}
}
最佳答案
我认为正确的解决方案是使用描述的方法之一将您的应用程序连接到应用程序见解 here 。从短期来看,为了让我的工作正常工作,我必须删除对 CreateEventSource()
的调用。并写入现有日志,因为我的应用程序无权在应用程序服务主机上创建新日志。
关于c# - 在 Azure 中使用事件日志(在事件查看器中写入),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38162718/