Registration error in ASP.Net Core 1 - description for xxxx event id from source application could not be found

I would like to write to the Windows event log from the Application Application ASP.NET Core method.

The problem is that when I expect the log information to be written, I keep getting the error / information log:

Description for event ID xxxx from source Application could not be found. Either the component that raises this event is not installed on your local computer or the installation is damaged. You can install or repair the component on the local computer.

If the event occurred on another computer, the displayed information should have been saved with the event.

The following information was included in the event:

My.Fully.Qualified.Namespace.WebApi.Controllers.MyController Error in the method "MyMethod"

message resource present but message not found in string / message

Be that as it may, before .Net Core, I always resolved a similar error by creating an event source using Powershell or Command or setting up Microsoft.Practices.EnterpriseLibrary.Logging app block or another third-party library

The approach I used was:

After installing the Nuget packages: Microsoft.Extensions.Logging.Abstractions and Microsoft.Extensions.Logging , I specify the EventLog provider in the Start Configure code block.

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory .AddDebug() .AddEventLog(); //... rest of the code here } 

For each controller, use the ILogger<T> approach :

 public class MyController : Controller { private readonly IMyRepository _myRepository; private readonly ILogger _logger; public MyController(IMyRepository myRepository, ILogger<MyController> logger) { _myRepository = myRepository; _logger = logger; } public bool MyMethod(MyRequestObject request) { try { var response = privateDoSomethingMethod(request); return response.Success; } catch (Exception ex) { _logger.LogError(6666,ex, "Error occured when doing stuff."); return false; } } 

This is based on official logging documentation.

What I read and tried:

+7
c # asp.net-core event-log
source share
1 answer

I could not use loggerFactory.AddEventLog () in .Net Core 2.0. Since Microsoft.Extensions.Logger.EventLog lives only in .net 4.5.1, although the Nuget package is available for 2.0.0 here , it seems that it needs to be ported to Core.

enter image description here

but maybe this will work for you. Add your CustomEventIds

  public static class CustomEventIds { public const int Debug = 100; public const int Information = 101; public const int Warning = 102; public const int Error = 103; public const int Critical = 104; } 

and

 _logger.LogInformation(CustomEventIds.Debug, "Starting to do something with input: {0}", "test"); 
+1
source share

All Articles