3 minutes to read read

NLog Targets

The beauty of NLog is the Targets ‘system’ that is extentible and easy to use. Also the most amazing thing is the default target list as provided by NLog and the ease with which custom targets can be written. The Targets provided by the Nlog  by default are more then sufficient for most needs.

There can be multiple targets that can be linked to multiple Rules.

Well, the currently provided targets as provided by NLog can be accessed here. Some of the most useful targets with sample configuration is as below:

  1. ColoredConsole: This target adds a ‘beautiful’ Colored logs on the console. Well from the name it applies for Console Applications only.
  2. File Target: The file target as form the names writes the log to any file. Also, the location of the file could be on the network path as well.

    There are two targets as defined above, one is normal file in local system and the other one is on network path. The archival options availabel for Files can be seen here
    There is also an possiblity to add more advanced options to control file parameters. An example code is given below as:
  3. Debug Target: As the name suggests it writes to the Log sink for the attached debugger  (if any :))
  4. Trace Target:  This also as prev, send the messages to system.Diagnoistics.Trace Listener. This can be useful, if there are any existing trace listeners, and nlog is to be configured to integrate with them.

Continue reading