question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Sublogger Ignoring Events from Parent Logger

See original GitHub issue

Does this issue relate to a new feature or an existing bug?

  • Bug
  • New Feature

What version of Serilog is affected? Please list the related NuGet package. Serilog.AspNetCore 2.1.1

What is the target framework and operating system? See target frameworks & net standard matrix.

  • netCore 2.0
  • netCore 1.0
  • 4.7
  • 4.6.x
  • 4.5.x

Please describe the current behavior? I set a Default MinimumLevel in my Serilog configuration of Debug, and override the MinumumLevel of one of my SourceContexts to “Verbose”. If I log directly to a Sink (File Sink, for example), it works as expected, with everything except the overridden source being filtered to Debug or higher, but Verbose events making it through for the overridden source. If I instead put a sub-logger between the main logger and the file sink (to add a filter or something), the Verbose events from the overridden source don’t make it through.

Here is a snippet from my appsettings.json configuration file:

  "Serilog": {
    "MinimumLevel": {
      "Default": "Debug",
      "Override": {
        "System": "Information",
        "Microsoft": "Information",
        "Namespace.BenchmarkTimer": "Verbose"
      }
    },
    "WriteTo": [
      {
        "Name": "Logger",
        "Args": {
          "configureLogger": {
            "Filter": [
              {
                "Name": "ByIncludingOnly",
                "Args": {
                  "expression": "StartsWith(SourceContext, 'Namespace.BenchmarkTimer')"
                }
              }
            ],
            "WriteTo": [
              {
                "Name": "File",
                "Args": {
                  "path": "d:\\path-to-log-folder\\Benchmark Timer.txt"
                }
              }
            ]
          }
        }
      }
    ]
  },

Please describe the expected behavior? All of the events from the parent logger make it through to the sinks configured in the sub-logger.

If the current behavior is a bug, please provide the steps to reproduce the issue and if possible a minimal demo of the problem Configure an application as described above. Write verbose logs from SourceContext “Namespace.BenchmarkTimer”. The verbose events will not make it to the sub-logger’s configured File Sink.

Note: I did try setting restrictedToMinimumLevel to “Verbose” on the sub-logger, which didn’t make a difference.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
maciejwcommented, Sep 24, 2019

@nblumhardt I’ll try to fix it 😃 I need this in my project 😉

0reactions
nblumhardtcommented, Jul 31, 2020

@tsimbalar @maciejw this isn’t the same issue as #967, as far as I can tell.

Read more comments on GitHub >

github_iconTop Results From Across the Web

MinimumLevel.Override not working inside child logger ...
The reason an information log event is propagating to the sink through the contextLogger , is because _overrideMap is only checked at the...
Read more >
Enable debug logging for just one sub logger (via config ...
I use the Python logging module in a rather "default" setup: Configuration happens via config file in the ini format and using ...
Read more >
Logging facility for Python — Python 3.11.4 documentation
When a logger is created, the level is set to NOTSET (which causes all messages to be processed when the logger is the...
Read more >
Issue 30862: parent logger should also check the level
Logging messages which are less severe than lvl will be ignored. When a logger is created, the level is set to NOTSET (which...
Read more >
A Complete Guide to Logging in Go with Zerolog
Event type to add relevant context to a log entry. This section will go one step further and show you how to add...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found