efcore: Diagnostics logging is incompatible with windows EventLog
After an upgrade to EF Core 2.0 EventLog provider throws an exception
Exception message: System.AggregateException: An error occurred while writing to logger(s). ---> System.ArgumentException: Invalid eventID value '100403'. It must be in the range between '0' and '65535'.
Stack trace: at System.Diagnostics.EventLogInternal.WriteEntry(String message, EventLogEntryType type, Int32 eventID, Int16 category, Byte[] rawData)
at System.Diagnostics.EventLog.WriteEntry(String message, EventLogEntryType type, Int32 eventID, Int16 category)
at Microsoft.Extensions.Logging.EventLog.WindowsEventLog.WriteEntry(String message, EventLogEntryType type, Int32 eventID, Int16 category)
at Microsoft.Extensions.Logging.EventLog.EventLogLogger.WriteMessage(String message, EventLogEntryType eventLogEntryType, Int32 eventId)
at Microsoft.Extensions.Logging.EventLog.EventLogLogger.Log[TState](LogLevel logLevel, EventId eventId, TState state, Exception exception, Func`3 formatter)
at Microsoft.Extensions.Logging.Logger.Log[TState](LogLevel logLevel, EventId eventId, TState state, Exception exception, Func`3 formatter)
--- End of inner exception stack trace ---
at Microsoft.Extensions.Logging.Logger.Log[TState](LogLevel logLevel, EventId eventId, TState state, Exception exception, Func`3 formatter)
at Microsoft.Extensions.Logging.LoggerMessage.<>c__DisplayClass8_0`4.<Define>b__0(ILogger logger, T1 arg1, T2 arg2, T3 arg3, T4 arg4, Exception exception)
at Microsoft.EntityFrameworkCore.Diagnostics.EventDefinition`4.Log[TLoggerCategory](IDiagnosticsLogger`1 logger, TParam1 arg1, TParam2 arg2, TParam3 arg3, TParam4 arg4, Exception exception)
at Microsoft.EntityFrameworkCore.Internal.CoreLoggerExtensions.ContextInitialized(IDiagnosticsLogger`1 diagnostics, DbContext context, DbContextOptions contextOptions)
at Microsoft.EntityFrameworkCore.DbContext.get_InternalServiceProvider()
at Microsoft.EntityFrameworkCore.DbContext.Microsoft.EntityFrameworkCore.Infrastructure.IInfrastructure<System.IServiceProvider>.get_Instance()
at Microsoft.EntityFrameworkCore.Infrastructure.DatabaseFacade.Microsoft.EntityFrameworkCore.Infrastructure.IInfrastructure<System.IServiceProvider>.get_Instance()
at Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.GetRelationalService[TService](IInfrastructure`1 databaseFacade)
at Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.Migrate(DatabaseFacade databaseFacade)
at AquaWeb.Portal.Services.SeedingService.<InitialiseDatabase>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at AquaWeb.Portal.Startup.Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IServiceScopeFactory serviceScopeFactory)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.AspNetCore.Hosting.ConventionBasedStartup.Configure(IApplicationBuilder app)
at Microsoft.ApplicationInsights.AspNetCore.ApplicationInsightsStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder app)
at Microsoft.AspNetCore.Server.IISIntegration.IISSetupFilter.<>c__DisplayClass3_0.<Configure>b__0(IApplicationBuilder app)
at Microsoft.AspNetCore.Hosting.Internal.AutoRequestServicesStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder builder)
at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()
---> (Inner Exception #0) System.ArgumentException: Invalid eventID value '100403'. It must be in the range between '0' and '65535'.
at System.Diagnostics.EventLogInternal.WriteEntry(String message, EventLogEntryType type, Int32 eventID, Int16 category, Byte[] rawData)
at System.Diagnostics.EventLog.WriteEntry(String message, EventLogEntryType type, Int32 eventID, Int16 category)
at Microsoft.Extensions.Logging.EventLog.WindowsEventLog.WriteEntry(String message, EventLogEntryType type, Int32 eventID, Int16 category)
at Microsoft.Extensions.Logging.EventLog.EventLogLogger.WriteMessage(String message, EventLogEntryType eventLogEntryType, Int32 eventId)
at Microsoft.Extensions.Logging.EventLog.EventLogLogger.Log[TState](LogLevel logLevel, EventId eventId, TState state, Exception exception, Func`3 formatter)
at Microsoft.Extensions.Logging.Logger.Log[TState](LogLevel logLevel, EventId eventId, TState state, Exception exception, Func`3 formatter)<---
Steps to reproduce
https://github.com/MaximBalaganskiy/EfEventLogIssue
Further technical details
Target Framework: net461 EF Core version: 2.0.0 Database Provider: Microsoft.EntityFrameworkCore.SqlServer Operating system: Windows 10 IDE: Visual Studio 2017
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 19 (16 by maintainers)
Commits related to this issue
- Make Event ID values smaller so they will work with Windows EventLog Issue #9437 All values now fit in a 16-bit unsigned int. There is a Quirks mode using the key "" to switch back to the 2.0.0 RTM ... — committed to dotnet/efcore by ajcvickers 7 years ago
- Make Event ID values smaller so they will work with Windows EventLog Issue #9437 All values now fit in a 16-bit unsigned int. There is a Quirks mode using the key "" to switch back to the 2.0.0 RTM ... — committed to dotnet/efcore by ajcvickers 7 years ago
- Make Event ID values smaller so they will work with Windows EventLog Issue #9437 All values now fit in a 16-bit unsigned int. There is a Quirks mode using the key "" to switch back to the 2.0.0 RTM ... — committed to dotnet/efcore by ajcvickers 7 years ago
- Remove quirking for event IDs added in 2.0.1 Because we generally only keep quirks in place until the next point release. Issue #9437 — committed to dotnet/efcore by ajcvickers 7 years ago
- Remove quirking for event IDs added in 2.0.1 Because we generally only keep quirks in place until the next point release. Issue #9437 — committed to dotnet/efcore by ajcvickers 7 years ago
I can confirm that the patch fixed this issue for me. Now I see EF logs in windows event log.