serilog-sinks-console
serilog-sinks-console copied to clipboard
How to make a colored tex into the console called by AllocConsole method?
I want to make "developer console" called in WinForm application by pressing hotkeys. The console is opened by calling AllocConsole, but the problem is that the text is displayed only in white color. Is there any way to solve this problem? I assume that I need to write something else in the code.
Exactly the same question. No any reaction on app.config settings.
Exactly the same question. No any reaction on app.config settings.
I have not found a solution. I'm happy with what I have and I'm already used to it.
@Hiprox , @ZedZipDev What about enabling the virtual terminal processing. Something like this.
AllocConsole()
auto hOut = GetStdHandle(STD_OUTPUT_HANDLE);
auto hIn = GetStdHandle(STD_INPUT_HANDLE);
auto hRealOut = CreateFile(L"CONOUT$", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_WRITE,0, CREATE_NEW, 0, 0);
auto hRealIn = CreateFile(L"CONIN$", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, 0, CREATE_NEW, 0, 0);
if (hRealOut != hOut)
{
SetStdHandle(STD_OUTPUT_HANDLE, hRealOut);
}
if (hRealIn != hIn)
{
SetStdHandle(STD_INPUT_HANDLE, hRealIn);
}
if (GetConsoleMode(hOut, &dConsoleMode))
{
dConsoleMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
SetConsoleMode(hOut, dConsoleMode);
}
You only need to create logger after using AllocConsole() for colors to work correctly. Virtual terminal support should be enabled by ConsoleSink:
https://github.com/serilog/serilog-sinks-console/blob/dev/src/Serilog.Sinks.Console/Sinks/SystemConsole/ConsoleSink.cs#L37