{"action":"created","issue":{"url":"https://api.github.com/repos/serilog/serilog-sinks-console/issues/27","repository_url":"https://api.github.com/repos/serilog/serilog-sinks-console","labels_url":"https://api.github.com/repos/serilog/serilog-sinks-console/issues/27/labels{/name}","comments_url":"https://api.github.com/repos/serilog/serilog-sinks-console/issues/27/comments","events_url":"https://api.github.com/repos/serilog/serilog-sinks-console/issues/27/events","html_url":"https://github.com/serilog/serilog-sinks-console/issues/27","id":270615746,"number":27,"title":"Colored output doesn't work with custom console stdout handle","user":{"login":"lennartb-","id":5563601,"avatar_url":"https://avatars2.githubusercontent.com/u/5563601?v=4","gravatar_id":"","url":"https://api.github.com/users/lennartb-","html_url":"https://github.com/lennartb-","followers_url":"https://api.github.com/users/lennartb-/followers","following_url":"https://api.github.com/users/lennartb-/following{/other_user}","gists_url":"https://api.github.com/users/lennartb-/gists{/gist_id}","starred_url":"https://api.github.com/users/lennartb-/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lennartb-/subscriptions","organizations_url":"https://api.github.com/users/lennartb-/orgs","repos_url":"https://api.github.com/users/lennartb-/repos","events_url":"https://api.github.com/users/lennartb-/events{/privacy}","received_events_url":"https://api.github.com/users/lennartb-/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2017-11-02T11:13:36Z","updated_at":"2017-11-03T08:58:56Z","closed_at":null,"author_association":"NONE","body":"Not sure if this is a bug or a limitation. We're using a customized console window in our application for debugging purposes. With VS 2017, Microsoft has done some [\"debug stdout](https://stackoverflow.com/a/45282476/368354) [redirect magic\"](https://developercommunity.visualstudio.com/content/problem/12166/console-output-is-gone-in-vs2017-works-fine-when-d.html) which broke color output with our console window. We fixed that by changing the color manually based on the logging level as suggested in the links above:\r\n\r\n```\r\nprivate static void SetForegroundColor(ConsoleColor color)\r\n{\r\n    using (var hConsoleOut = new SafeFileHandle(CreateFile(OurCustomConsoleFileHandleName, GenericWrite, FileShareWrite, 0, OpenExisting, 0, 0), true))\r\n    {\r\n        SetConsoleTextAttribute(hConsoleOut.DangerousGetHandle(), (ushort) color);\r\n    }\r\n}\r\n```\r\nHowever, when using the console sink, we now don't have any colored output again. I took a look at the `ConsoleSink `class, and wrapped the calls in the Emit() method with two `SetForegroundColor()` calls that set the color based on the `logEvent.Level` and re-set it to the default color after writing the output.\r\n\r\nThis already worked to my surprise, but I also had to edit the `ConsoleLoggerConfigurationExtensions` to use my customized version and add some reflection to deal with the referenced internal classes, which is more of a hack than a proper solution.\r\n\r\nIs there something I overlooked in the configuration where I could have changed that without changing the existing sink?\r\n\r\nVersions:\r\n* Serilog 2.5.0\r\n* Serilog.Sinks.Console 3.1.1\r\n\r\nSystem:\r\n* Windows 10 Pro x64\r\n* WPF application with .NET 4.6.1\r\n* VS 2017 Enterprise 15.4.2\r\n"},"comment":{"url":"https://api.github.com/repos/serilog/serilog-sinks-console/issues/comments/341649482","html_url":"https://github.com/serilog/serilog-sinks-console/issues/27#issuecomment-341649482","issue_url":"https://api.github.com/repos/serilog/serilog-sinks-console/issues/27","id":341649482,"user":{"login":"lennartb-","id":5563601,"avatar_url":"https://avatars2.githubusercontent.com/u/5563601?v=4","gravatar_id":"","url":"https://api.github.com/users/lennartb-","html_url":"https://github.com/lennartb-","followers_url":"https://api.github.com/users/lennartb-/followers","following_url":"https://api.github.com/users/lennartb-/following{/other_user}","gists_url":"https://api.github.com/users/lennartb-/gists{/gist_id}","starred_url":"https://api.github.com/users/lennartb-/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lennartb-/subscriptions","organizations_url":"https://api.github.com/users/lennartb-/orgs","repos_url":"https://api.github.com/users/lennartb-/repos","events_url":"https://api.github.com/users/lennartb-/events{/privacy}","received_events_url":"https://api.github.com/users/lennartb-/received_events","type":"User","site_admin":false},"created_at":"2017-11-03T08:58:56Z","updated_at":"2017-11-03T08:58:56Z","author_association":"NONE","body":"Hi, I tried that, but can't get it to work. I tried to just copy the AnsiConsoleTheme, but the Set() method is never called. I configured it like this:\r\n\r\n```\r\n Log.Logger = new LoggerConfiguration()\r\n .WriteTo.Console(outputTemplate: fileOutputTemplate, theme: new DynConsoleTheme(dict))\r\n.CreateLogger();\r\n\r\n```\r\nwhere `dict `is one of the dictionaries I copied from `SystemConsoleThemes`."}}
{"actor":{"display_login":"lennartb-"}}