-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Console target
Writes log messages to the console.
Platforms Supported: Limited (Not available for NetStandard1.3)
There is also the colorful ColoredConsole-Target that can highlight single words or color entire rows.
<targets>
<target xsi:type="Console"
name="String"
layout="Layout"
footer="Layout"
header="Layout"
encoding="Encoding"
stderr="Boolean"
detectConsoleAvailable="Boolean"
writeBuffer="Boolean" />
</targets>
Read more about using the Configuration File.
- name - Name of the target.
-
layout - Text to be rendered. Layout Required. Default:
${longdate}|${level:uppercase=true}|${logger}|${message:withexception=true}
- footer - Footer. Layout
- header - Header. Layout
-
encoding - File encoding name like "utf-8", "ascii" or "utf-16". See Encoding class on MSDN. Defaults to
Encoding.Default
.Introduced in NLog 4.0.
-
StdErr - Indicates whether the error stream (stderr) should be used instead of the output stream (stdout). Boolean Default:
false
Before NLog v5.0 the property was named
error
. -
detectConsoleAvailable - Indicates whether the console target should disable itself when no console detected. Boolean Default:
false
Introduced in NLog 4.3.10 with default:
true
, then NLog 4.4 changed default tofalse
. -
autoFlush - Performs explicit flush after every console write. Useful if having redirected to custom console-stream that doesn't has autoflush enabled. Boolean. Default = False.
Introduced in NLog 4.6.3
-
WriteBuffer - Instead of calling
Console.WriteLine
then it writes buffer directly toConsole.Write
. When combined with AsyncWrapper it will allow batching and double output performance. Useful when redirecting console in cloud-function. Default:False
.Introduced with NLog v4.6.8
<target name="Console" xsi:type="Console" layout="${longdate} ${logger} ${level} ${message}"/>
- Troubleshooting Guide - See available NLog Targets and Layouts: https://nlog-project.org/config
- Getting started
- How to use structured logging
- Troubleshooting
- FAQ
- Articles about NLog
-
All targets, layouts and layout renderers
Popular: - Using NLog with NLog.config
- Using NLog with appsettings.json