mperdeck / jsnlog

JSNLog for .Net. Combines jsnlog.js client side logging with .Net server side component to receive log messages and pass them to the server side logging package. Configure loggers in web.config.
jsnlog.com
MIT License
190 stars 38 forks source link

JSNLog.Serilog doesn't set Serilog's SourceContext property #181

Closed rocknet closed 5 years ago

rocknet commented 5 years ago

Hi. I'm working on an upgrade from JSNLog.Log4Net to JSNLog.Serilog as part of a larger migration to structured logging. Previously, we set our server side logger name to ClientSideJS, we currently don't get that as expected in the Serilog SourceContext property.

I did enough investigation to know that it's because Common.Logging.Serilog.StructuredText was forked and not kept up to date. The initial commit here used ForContext("name", name), but over the years the upstream has been properly updated to use the SourceContext property.

I'm not sure why you needed to fork this rather than just adding a NuGet dependency, but assuming there's a need for that fork - and keeping it where it is - would you accept a PR to change "name" to "SourceContext" in SerilogFactoryAdapter? If not, do you have any other suggestions? The JSNLog.Serilog package depends on this package, so it'd be a maintenance headache to not use it somehow.

Reference: https://github.com/serilog/serilog/wiki/Writing-Log-Events#source-contexts

mperdeck commented 5 years ago

Apologies for the late reply. I would be happy to accept a pull request from you to fix this issue.

PaulUpson commented 5 years ago

Hi @mperdeck we are also considering using JSNLog.Serilog but require this issue resolved before we can move forward. Please see my PR.

epozsh commented 5 years ago

@mperdeck Hi, can you please make a working sample for Asp .Net Core 2.2 - Serilog - JSNlog?

mperdeck commented 5 years ago

@Shadowman4205 ASP.NET Core has its own logging infrastructure in which logging packages such as Serilog can be plugged (similar to Common.Logging). JSNLog simply talks to that infrastructure. Serilog has good support for ASP.NET Core. If you google this, you should be able to plug Serilog into the ASP.NET Core logging infrastructure.