-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Debug target
Rolf Kristensen edited this page Dec 2, 2023
·
15 revisions
Mock target for unit-testing. If looking for output to System.Diagnostics.Debug
then use DebugSystem-target.
Platforms Supported: All
<targets>
<target xsi:type="Debug" name="String" layout="Layout" />
</targets>
Read more about using the Configuration File.
- name - Name of the target.
-
layout - Layout used to format log messages. Layout Required. Default:
${longdate}|${level:uppercase=true}|${logger}|${message:withexception=true}
(snippet from Debug Simple Example.cs )
NLog.Targets.DebugTarget target = new NLog.Targets.DebugTarget() { Name = "Debug" };
target.Layout = "${message}";
NLog.Config.LoggingConfiguration config = new NLog.Config.LoggingConfiguration();
config.AddRuleForAllLevels(target)
NLog.LogManager.Configuration = config;
NLog.Logger logger = NLog.LogManager.GetLogger("Example");
logger.Debug("log message");
logger.Debug("another log message");
Console.WriteLine("The debug target has been hit {0} times.", target.Counter);
Console.WriteLine("The last message was '{0}'.", target.LastMessage);
Some examples of DebugTarget use can be found in unit tests
- Troubleshooting Guide - See available NLog Targets and Layouts: https://nlog-project.org/config
- Getting started
- How to use structured logging
- Troubleshooting
- FAQ
-
All targets, layouts and layout renderers
Popular: - Using NLog with NLog.config
- Using NLog with appsettings.json