SelfLog not writing to Text File
See original GitHub issueI’m trying to debug an issue where ‘some’ of our logs never appear in LogAnalytics using the Serilog.Sinks.AzureAnalytics (see issue here https://github.com/saleem-mirza/serilog-sinks-azure-analytics/issues/42).
.NET Core 2.1 api, using: Serilog.AspNetCore 2.1.1 Serilog.Sinks.AzureAnalytics 4.0.0
Based on your wiki under the Debug and Diagnose section I’m doing the following as the first statements in my startup.cs:
var file = File.CreateText("myFilePath"); Serilog.Debugging.SelfLog.Enable(TextWriter.Synchronized(file)); Serilog.Debugging.SelfLog.Enable(msg => Debug.WriteLine(msg)); Serilog.Debugging.SelfLog.Enable(Console.Error);
The other debug outputs work fine and I can see the batch logs, but the logging to the file is empty.
The file does indeed get created, it’s just empty.
I’ve seen other issues on here stating to use Log.CloseAndFlush(); but I can’t do this as this is a continuously running api.
Am I missing something vital?
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (2 by maintainers)
Top Related StackOverflow Question
Hi,
Every time you call
SelfLog.Enable(...), you replace previous Selflog error handler …Which means that :
If you want the
SelfLogto write to multiple outputs, you need to do it all in a singleSelfLog.Enable()call like :I hope this helps !
(you may also want to
try/catcharound the writing to file just in case …Another Sample that append the Serilog Internal Errors to a file