0

How I can do logger.Information() in method, If I have LogLevel:Error.

Here's my serilog configuration in appsettings.json :


"Serilog": {
    "MinimumLevel": {
      "Default": "Error"
      }
    },
    "WriteTo": [
      {
        "Name": "Console"
      }
    ]
}

spaleet
  • 838
  • 2
  • 10
  • 23
Daniel
  • 61
  • 6
  • ? If you want to log "information" messages, you need to set the logger level to "information". If you want to keep the level at "error", but still need to report a message, it needs to be "error" or worse. – JHBonarius Feb 17 '22 at 14:52
  • But if I want to log information only in one method? Can I do it? – Daniel Feb 17 '22 at 15:12
  • Yes, but IMHO it could be code smell and you should then probably look for a better solution. See [the manual](https://github.com/serilog/serilog-settings-configuration) for "Override"-ing the logging levels of separate paths/namespaces. – JHBonarius Feb 17 '22 at 15:31
  • Don`t know why, but overide doesn`t work with namespaces. In works well with "Microsoft". But when i try to override for "MyProject.Class" it doesn`t work – Daniel Feb 17 '22 at 15:36
  • "MyProject. **Class**" doesn't sound like a namespace, but a class name. "MyProject" should work as namespace. You should probably put the class in a separate namespace... – JHBonarius Feb 17 '22 at 15:39
  • Yes, I`ve done it. But desn`t work – Daniel Feb 17 '22 at 15:40
  • Maybe you should give a [mcve]... – JHBonarius Feb 17 '22 at 15:42
  • No, it is not possible to set the log level in a single method only. You can change the log level per environment. Like, have your local machine log info but log only errors in production or stage environment. – beautifulcoder Feb 21 '22 at 01:56

0 Answers0