ColoredConsoleTarget Class |
Namespace: NLog.Targets
The ColoredConsoleTarget type exposes the following members.
| Name | Description | |
|---|---|---|
| ColoredConsoleTarget |
Initializes a new instance of the ColoredConsoleTarget class.
| |
| ColoredConsoleTarget(String) |
Initializes a new instance of the ColoredConsoleTarget class.
|
| Name | Description | |
|---|---|---|
| AutoFlush |
Gets or sets a value indicating whether to auto-flush after WriteLine | |
| DetectConsoleAvailable |
Gets or sets a value indicating whether to auto-check if the console is available.
- Disables console writing if Environment.UserInteractive = (Windows Service)
- Disables console writing if Console Standard Input is not available (Non-Console-App)
| |
| DetectOutputRedirected |
Gets or sets a value indicating whether to auto-check if the console has been redirected to file
- Disables coloring logic when System.Console.IsOutputRedirected = | |
| EnableAnsiOutput |
Enables output using ANSI Color Codes
| |
| Encoding |
The encoding for writing messages to the Console.
| |
| Footer |
Gets or sets the footer.
(Inherited from TargetWithLayoutHeaderAndFooter.) | |
| Header |
Gets or sets the header.
(Inherited from TargetWithLayoutHeaderAndFooter.) | |
| Layout |
Gets or sets the layout used to format log messages.
(Inherited from TargetWithLayoutHeaderAndFooter.) | |
| Name |
Gets or sets the name of the target.
(Inherited from Target.) | |
| NoColor |
Support NO_COLOR=1 environment variable. See also https://no-color.org/ | |
| RowHighlightingRules |
Gets the row highlighting rules.
| |
| StdErr |
Gets or sets a value indicating whether to send the log messages to the standard error instead of the standard output.
| |
| UseDefaultRowHighlightingRules |
Gets or sets a value indicating whether to use default row highlighting rules.
| |
| WordHighlightingRules |
Gets the word highlighting rules.
|
| Name | Description | |
|---|---|---|
| Dispose |
Closes the target.
(Inherited from Target.) | |
| Flush |
Flush any pending log messages (in case of asynchronous targets).
(Inherited from Target.) | |
| PrecalculateVolatileLayouts |
Calls the Precalculate(LogEventInfo) on each volatile layout
used by this target.
This method won't prerender if all layouts in this target are thread-agnostic.
(Inherited from Target.) | |
| ToString | Returns a string that represents the current object. (Inherited from Target.) | |
| WriteAsyncLogEvent |
Writes the log to the target.
(Inherited from Target.) | |
| WriteAsyncLogEvents(AsyncLogEventInfo) |
Writes the array of log events.
(Inherited from Target.) | |
| WriteAsyncLogEvents(IListAsyncLogEventInfo) |
Writes the array of log events.
(Inherited from Target.) |
To set up the target in the configuration file, use the following syntax:
1!ERROR: See log file!To set up the log target programmatically use code like this:
1using NLog; 2using NLog.Config; 3using NLog.Targets; 4 5class Example 6{ 7 static void Main(string[] args) 8 { 9 ColoredConsoleTarget target = new ColoredConsoleTarget(); 10 target.Layout = "${date:format=HH\\:MM\\:ss} ${logger} ${message}"; 11 12 LoggingConfiguration nlogConfig = new LoggingConfiguration(); 13 nlogConfig.AddRuleForAllLevels(target); 14 LogManager.Configuration = nlogConfig; 15 16 Logger logger = LogManager.GetLogger("Example"); 17 logger.Trace("trace log message"); 18 logger.Debug("debug log message"); 19 logger.Info("info log message"); 20 logger.Warn("warn log message"); 21 logger.Error("error log message"); 22 logger.Fatal("fatal log message"); 23 } 24}