No EventLog for Aspnet Core with Nlog
If you trying to pass a json object you can still do so just not with the EventLog object. Instead just use the MS LogIformation method with the object as your parameters. I still havent got it to format the json object in the logs but for now this is a solution.
Another solution is to pull the nlog object in and not use the MS LogInformation in
Logger log = LogManager.GetCurrentClassLogger();
I haven't done this yet but I dont see a logical issue just bad design
- https://github.com/NLog/NLog/issues/2106
- https://stackoverflow.com/questions/39099601/how-can-i-configure-json-format-indents-in-asp-net-core-web-api
- https://github.com/NLog/NLog/issues/2629
- https://stackoverflow.com/questions/34679727/use-nlog-in-asp-net-core-application
- https://stackoverflow.com/questions/44048187/layout-nlog-properties-as-json
- Example: https://github.com/NLog/NLog.Web/blob/master/examples/ASP.NET%20Core%203/ASP.NET%20Core%203%20-%20VS2019/Controllers/HomeController.cs
- https://github.com/NLog/NLog/wiki/JsonLayout#nested-json-with-structured-logging
More Improvements: https://blog.elmah.io/nlog-tutorial-the-essential-guide-for-logging-from-csharp/
Global Diagnostics Context
This context is implemented in the GlobalDiagnosticsContext
class and represents a dictionary spanning the entire lifetime of your application. This context is great for including global properties to all log messages. A global property could be the name of the application, the version number, or other common information that you want access to on all log messages.
Adding properties to the global context can be done in your startup/initialization code like this:
GlobalDiagnosticsContext.Set("Application", "My cool app");
GlobalDiagnosticsContext.Set("Version", "1.0.42");