stevejgordon / CorrelationId

An ASP.NET Core middleware component which synchronises a correlation ID for cross API request logging.
MIT License
559 stars 106 forks source link

Disable internal logging #90

Closed dmytrohridin closed 4 years ago

dmytrohridin commented 4 years ago

Use case Our application writes a lot of info into logs, but the library produces some info logs too, that is redundant for us. For sure, we can somehow filter messages produced by the library.

Proposal Implement enabling/disabling logging for the library or make library log level configurable (i.e. write only errors)

If idea makes sense - I can submit PR

Thank you

wdolek commented 4 years ago

Hi @dmytrohridin, would it be possible to just disable it with logging configuration like this:

{
  "Logging": {
    "LogLevel": {
      /* ... */
      "CorrelationId": "Error"
    }
  },
  "AllowedHosts": "*"
}

... this will keep logging errors (currently only when correlation ID is not configured), or you can set value to None.

dmytrohridin commented 4 years ago

@wdolek I tried in this way, but it's not working (I use Serilog)

wdolek commented 4 years ago

@dmytrohridin I haven't used Serilog much yet, but this looks like configuration which could help (Serilog 2.1+):

Log.Logger = new LoggerConfiguration()
    // ...
    .MinimumLevel.Override("CorrelationId", LogEventLevel.Error);

... or there may be other ways of filtering. I can understand that adding bool flag would be the easiest for user though.

dmytrohridin commented 4 years ago

@wdolek nice idea, will try, thank you

dmytrohridin commented 4 years ago

it works, thank you, will close issue

stevejgordon commented 4 years ago

Thanks for providing the solution @wdolek!