Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从System.Diagnostics.EventLoginInternal.InternalWriteEvent写入记录器时出错_C#_Asp.net Core_.net Core_Azure Web App Service - Fatal编程技术网

C# 从System.Diagnostics.EventLoginInternal.InternalWriteEvent写入记录器时出错

C# 从System.Diagnostics.EventLoginInternal.InternalWriteEvent写入记录器时出错,c#,asp.net-core,.net-core,azure-web-app-service,C#,Asp.net Core,.net Core,Azure Web App Service,我在Azure的应用程序服务中遇到了一个web API的随机异常。我不认为这是与我的代码相关的问题。以下是Application Insights中的错误消息和堆栈跟踪: Message An error occurred while writing to logger(s). (The process cannot access the file because it is being used by another process) The process cannot access the

我在Azure的应用程序服务中遇到了一个web API的随机异常。我不认为这是与我的代码相关的问题。以下是Application Insights中的错误消息和堆栈跟踪:

Message An error occurred while writing to logger(s). (The process cannot access the file because it is being used by another process) The process cannot access the file because it is being used by another pr…[show more]    
Exception type  System.ComponentModel.Win32Exception    
Failed method   System.Diagnostics.EventLogInternal.InternalWriteEvent
使用以下堆栈跟踪:

System.AggregateException:
   at Microsoft.Extensions.Logging.Logger.Log (Microsoft.Extensions.Logging, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
   at Microsoft.Extensions.Logging.Logger`1.Microsoft.Extensions.Logging.ILogger.Log (Microsoft.Extensions.Logging.Abstractions, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
   at Microsoft.Extensions.Logging.LoggerMessage+<>c__DisplayClass6_0`2.<Define>b__0 (Microsoft.Extensions.Logging.Abstractions, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
   at Microsoft.AspNetCore.Mvc.Internal.MvcCoreLoggerExtensions.ActionMethodExecuting (Microsoft.AspNetCore.Mvc.Core, Version=2.2.5.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker+<InvokeActionMethodAsync>d__12.MoveNext (Microsoft.AspNetCore.Mvc.Core, Version=2.2.5.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker+<InvokeNextActionFilterAsync>d__10.MoveNext (Microsoft.AspNetCore.Mvc.Core, Version=2.2.5.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow (Microsoft.AspNetCore.Mvc.Core, Version=2.2.5.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next (Microsoft.AspNetCore.Mvc.Core, Version=2.2.5.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker+<InvokeInnerFilterAsync>d__13.MoveNext (Microsoft.AspNetCore.Mvc.Core, Version=2.2.5.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker+<InvokeNextResourceFilter>d__23.MoveNext (Microsoft.AspNetCore.Mvc.Core, Version=2.2.5.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow (Microsoft.AspNetCore.Mvc.Core, Version=2.2.5.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next (Microsoft.AspNetCore.Mvc.Core, Version=2.2.5.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker+<InvokeFilterPipelineAsync>d__18.MoveNext (Microsoft.AspNetCore.Mvc.Core, Version=2.2.5.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker+<InvokeAsync>d__16.MoveNext (Microsoft.AspNetCore.Mvc.Core, Version=2.2.5.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at Microsoft.AspNetCore.Builder.RouterMiddleware+<Invoke>d__4.MoveNext (Microsoft.AspNetCore.Routing, Version=2.2.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware+<Invoke>d__6.MoveNext (Microsoft.AspNetCore.Authentication, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at Microsoft.AspNetCore.Server.IIS.Core.IISHttpContextOfT`1+<ProcessRequestAsync>d__2.MoveNext (Microsoft.AspNetCore.Server.IIS, Version=2.2.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
Inner exception System.ComponentModel.Win32Exception handled at Microsoft.Extensions.Logging.Logger.Log:
   at System.Diagnostics.EventLogInternal.InternalWriteEvent (System.Diagnostics.EventLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51)
   at System.Diagnostics.EventLogInternal.WriteEvent (System.Diagnostics.EventLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51)
   at Microsoft.Extensions.Logging.EventLog.WindowsEventLog.WriteEntry (Microsoft.Extensions.Logging.EventLog, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
   at Microsoft.Extensions.Logging.EventLog.EventLogLogger.WriteMessage (Microsoft.Extensions.Logging.EventLog, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
   at Microsoft.Extensions.Logging.EventLog.EventLogLogger.Log (Microsoft.Extensions.Logging.EventLog, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
   at Microsoft.Extensions.Logging.Logger.Log (Microsoft.Extensions.Logging, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)

任何关于这一想法的帮助都是有益的。

在Azure中运行的.NET Core 3.1.0 Web API应用程序中,我有一个应用程序在写入EventLogger时遇到了相同的问题。我们正在使用内置ILogger和NLog来保存日志,以Stackify和Raygun

我们的应用程序使用了MediatR库,我们用额外的日志记录对管道执行进行了包装,这样每次执行不同的命令时,我们都会记录所花的时间。我们的应用程序广泛使用日志记录。这些问题大多发生在用户活动显著增加时

这些错误将以AggregateException的形式显示在日志中:

写入记录器时出错。(该进程无法访问该文件,因为另一进程正在使用该文件。)

除了内部例外:

System.Diagnostics.EventLoginInternal.InternalWriteEvent(UInt32事件ID,UInt16类别,EventLogEntryType类型,字符串[]字符串,字节[]原始数据,字符串currentMachineName)
System.Diagnostics.EventLoginInternal.WriteEvent(EventInstance实例,字节[]数据,对象[]值):170
Microsoft.Extensions.Logging.EventLog.WindowsEventLog.WriteEntry(字符串消息,EventLogEntryType类型,Int32 eventID,Int16类别):129
Microsoft.Extensions.Logging.EventLogger.WriteMessage(字符串消息,EventLogEntryType EventLogEntryType,Int32 eventId):158
Microsoft.Extensions.Logging.EventLogger.Log[TState](日志级别LogLevel,EventId EventId,TState状态,异常,Func3格式化程序)
Microsoft.Extensions.Logging.Logger.g|u LoggerLog | 12_0[TState](LogLevel LogLevel,EventId EventId,ILogger Logger,异常异常,Func3格式化程序,列表1和异常,TState和状态):45

我们基本上会看到数百个这样的错误,这将导致我们的应用程序变得无响应和超时请求。但是--我们的应用程序不需要EventSource日志记录,因此我们采纳了@Dan Kroymann的建议,从Progam.cs中配置的日志记录提供程序中删除了EventLog,例如

public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
            .ConfigureLogging((hostingContext, logging) =>
            {
                logging.ClearProviders();
                logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
                logging.AddDebug();
                logging.AddConsole();
            })
            .ConfigureWebHostDefaults(webBuilder => webBuilder
                .UseStartup<Startup>()
                .UseNLog());
公共静态IHostBuilder CreateHostBuilder(字符串[]args)=>
Host.CreateDefaultBuilder(args)
.ConfigureLogging((hostingContext,logging)=>
{
logging.ClearProviders();
logging.AddConfiguration(hostingContext.Configuration.GetSection(“logging”));
logging.AddDebug();
logging.AddConsole();
})
.ConfigureWebHostDefaults(webBuilder=>webBuilder
.UseStartup()
.UseNLog());
为了使用某些日志扩展方法,您可能需要参考其他nuget软件包:

Microsoft.Extensions.Logging

Microsoft.Extensions.Logging.Console

Microsoft.Extensions.Logging.Debug


一旦我们安装了上述修复程序,我们就不再看到EventSource日志记录问题。

您是否尝试重新启动应用程序服务?你们看到这种情况一直发生吗?你们最终找到原因了吗?不,我仍然在应用程序中看到这些错误insight@BhargaviAnnadevara-MSFT我尝试重新启动应用程序服务,但没有帮助。@BhargaviAnnadevara MSFT我在我的许多应用程序服务中都看到了这一点。我的分析表明,当日志记录尝试大量出现时(例如,当SQL数据库之类的依赖项失败,导致大量请求抛出异常时),就会发生这种情况。一些错误日志记录调用最终会遇到此异常,这反过来会生成更多日志记录,从而进一步加剧问题。最近,为了避免这个问题,我开始从我的应用程序配置中删除事件日志记录提供程序。如果我们确实需要事件日志怎么办?@Dagrooms那么我可能建议创建一个静态ApplicationLogger,在启动时注册,并在整个应用程序中使用它。您需要确保资源(在本例中为EventLog)不被并发访问。
{
  "Logging": {
    "LogLevel": {
      "Default": "Debug",
      "System": "Information",
      "Microsoft": "Information"
    }
  }
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
            .ConfigureLogging((hostingContext, logging) =>
            {
                logging.ClearProviders();
                logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
                logging.AddDebug();
                logging.AddConsole();
            })
            .ConfigureWebHostDefaults(webBuilder => webBuilder
                .UseStartup<Startup>()
                .UseNLog());