0

In a recent project, I have loggings, looking like this:

2022-09-03 00:00:00.7450 | Debug | Company.Server.Communication.Connection.SendMS | Try to send Status 

In an older project I've taken over, loggings look like this:

2023-06-05 14:33:01.3051 | Company.Server.OpenAccess.Manager | Configuring database manager

In other words,
the more recent style is Date | Level | Class | free text,
while:
the older style is Date | Class | free text.

In order to open the logger instance, the following line is used:

private static readonly Logger Log = LogManager.GetCurrentClassLogger();

I have no idea where the configuration of my logger is saved.

I would like to add the loglevel (Info, Debug, ...) to the logging, but I don't even know where the Log.Debug() command gets its configuration information from (which NLog.xml, is there an NLog.config or an NLog entry in the *.csproj files, ...).

How can I find the logging configuration and how do I need to modify it?

Thanks in advance

Dominique
  • 16,450
  • 15
  • 56
  • 112
  • There are 2 ways to change your NLog configuration. Either [programmatically](https://github.com/NLog/NLog/wiki/Configure-from-code) or with a [configuration file](https://github.com/nlog/NLog/wiki/Configuration-file) – Roe Jun 05 '23 at 12:59
  • Did you look up [all the possible places for configs](https://github.com/nlog/NLog/wiki/Configuration-file#file-locations) and checked them off one by one? What happens if you _add_ one? Is there a programmatic one? – Fildor Jun 05 '23 at 13:00
  • @Roe: how can I know which way is used? I know there are different ways to do it. In top of this, I'm working in multiple directories (one for the main application, one for the DLLs, ...). – Dominique Jun 05 '23 at 13:02
  • _" I'm working in multiple directories"_ - what does that mean? The _configuration_ still should be in _one_ place. Even if you define different targets for the main application and libraries (which is kind of odd, by ok...) – Fildor Jun 05 '23 at 13:05
  • @Dominique to find this out you will have to first search for any code ressembling or containing code from the NLog library. If you don't find any search in your directory for NLog.text. This is all described in the examples I commented – Roe Jun 05 '23 at 13:07
  • @Fildor: I'm working with an application, loading a bunch of DLLs. The application is located in the main folder, while the DLLs are located in the "Modules" subfolder. Both directories have an `nlog.xml` file, and I don't know which one of those is used (or even possibly another file). – Dominique Jun 05 '23 at 13:25
  • For your information: both `NLog.xml` files contain quite a lot of entries like the following `${longdate}|${level:uppercase=true}|${logger}|${message}`. As you see, the loglevel is included, so I believe these are not the entries which are taken into account. – Dominique Jun 05 '23 at 13:27
  • I'm reading through the documentation and i don't see `level:uppercase=true` as valid value for level. You can set a `minlevel`, `maxlevel` and `level` where only 7 values are valid: `Trace`, `Debug`, `Info`, `Warn`, `Error`, `Fatal` and `off`. This is all documented inside this [page](https://github.com/nlog/NLog/wiki/Configuration-file) – Roe Jun 05 '23 at 13:35
  • 2
    _"Both directories have an nlog.xml file"_ - remove both and introduce one proper one. Also, enable [self-logging](https://github.com/nlog/nlog/wiki/Logging-troubleshooting#internal-logging) so you can see, where the config is pulled from and if it is valid. – Fildor Jun 05 '23 at 14:20
  • 1
    There is a trouble-shooting guide, too: https://github.com/nlog/nlog/wiki/Logging-troubleshooting – Fildor Jun 05 '23 at 14:21
  • @Fildor: I won't accept it as the final answer, but an answer, mentioning a trouble-shooting guide, deserves an upvote. – Dominique Jun 05 '23 at 14:30

0 Answers0