-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ColoredConsole - Log message not colored "strange characters" before and after message #4480
Comments
Hi! Thanks for opening your first issue here! Please make sure to follow the issue template - so we could help you better! |
You can enable global support for ANSI color codes by enabling Windows 10 VT (Virtual Terminal):
Alternative your application can call static class WindowsConsole
{
public static void EnableVirtualTerminal()
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
return;
var stdout = GetStdHandle(StandardOutputHandleId);
if (stdout != (IntPtr)InvalidHandleValue && GetConsoleMode(stdout, out var mode))
{
SetConsoleMode(stdout, mode | EnableVirtualTerminalProcessingMode);
}
}
const int StandardOutputHandleId = -11;
const uint EnableVirtualTerminalProcessingMode = 4;
const long InvalidHandleValue = -1;
[DllImport("kernel32.dll", SetLastError = true)]
static extern IntPtr GetStdHandle(int handleId);
[DllImport("kernel32.dll", SetLastError = true)]
static extern bool GetConsoleMode(IntPtr handle, out uint mode);
[DllImport("kernel32.dll", SetLastError = true)]
static extern bool SetConsoleMode(IntPtr handle, uint mode);
} But yes it is very annoying ANSI-Coloring is not just working out of the box everywhere. Maybe Windows 11 will be different. See also: https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences |
I was still bothered by this "not working"... I found my problem:
|
Yes if you stop using |
NLog version:
NLog: 4.7.10
NLog.Extensions.Hosting: 1.7.3
Platform:
.NET 5 (5.0.7) - Console Application
Win10x64 21H1
Current NLog config (xml or C#, if relevant)
- Did you checked the Internal log?
No errors in log.
- Are there any workarounds? yes/no
I don't know any.
- What is the current result?
When running the application from VS or using the standard windows cmd/powershell shell the log messages are not displayed in color (see screenshot):
Please note the "←[35m0" and "←[0m" at the start and end of the log entry.
Coloring works in ConEmu:
- What is the expected result?
Color output should work in all shells.
The text was updated successfully, but these errors were encountered: