简体   繁体   中英

C#: Regarding Nlog settings and usage

i am curious to use nlog. i did not use it previously. so i like to use it now in my project. i have a question.

<rules>
    <logger name="SomeNamespace.Component.*" minlevel="Trace" writeTo="logfile" final="true" />
    <logger name="*" minlevel="Info" writeTo="logfile" />
</rules>

what does mean here SomeNamespace.Component.* ? show me the usage of this type of rule with sample code

what is minlevel="Info" ? what does mean minlevel here ? what other option can be set for minlevel ?

thanks

what does mean here SomeNamespace.Component.* ?

It means that this rule will match any loggers which have name starting with SomeNamespace.Component. . Usually name of logger equals name of class where you are creating logger (but you also can provide custom logger name):

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

So rule configuration above will match following logger names:

SomeNamespace.Component.MyClass
SomeNamespace.Component.Cool.Other.Namespace.YourClass
// etc

Ie any logger created in class from SomeNamespace.Component. namespace will match rule. No matter how many classes with loggers you have there.

what is minlevel="Info" ?

It's a minimal level of log messages which will be logged by logger.

Logger.Debug("This will not be logged");
Logger.Info("This will be logged");

NLog supports following log levels (you can use any of them to control which messages will be logged):

  1. Trace
  2. Debug
  3. Info
  4. Warn
  5. Error
  6. Fatal

Check description of each level at NLog wiki . Usually you should use min level Info which will log any error messages and some high-level details of what system is doing. For debugging purpose you can turn-on Trace or Debug level, but your log file can become huge very quickly. Performance also will hurt when you are writing lot of log messages.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM