serilog-extensions-logging | Serilog provider
kandi X-RAY | serilog-extensions-logging Summary
kandi X-RAY | serilog-extensions-logging Summary
A Serilog provider for Microsoft.Extensions.Logging, the logging subsystem used by ASP.NET Core.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of serilog-extensions-logging
serilog-extensions-logging Key Features
serilog-extensions-logging Examples and Code Snippets
Community Discussions
Trending Discussions on serilog-extensions-logging
QUESTION
I'm trying to use Serilog's AddFile
by way of LoggerFactory but I can't get it to do anything.
This is my appsettings.json
, unchanged from the getting started guide.
Here is what I have:
...ANSWER
Answered 2021-Sep-06 at 12:51The Serilog extension you're using (Serilog.Extensions.Logging.File) internally writes to the file asynchronously on a separate thread, and your application is terminating before Serilog had the chance to flush the logs to the file on disk (which could take about ~2 seconds).
Normally you'd use an application host that takes care of disposing the logger (and other services) before the application terminates, forcing a flush which would write to disk, but in your case with a simple Console app, nobody is disposing the log so there's no final flush happening before the app terminates.
Serilog has a Log.CloseAndFlush
method that is normally used in cases like this and you're expected to call it before your app terminates, however Log.CloseAndFlush
doesn't work with Serilog.Extensions.Logging.File (at least with the latest version as of this writing) because it doesn't assign the logger it creates to Log.Logger
which is what CloseAndFlush
tries to dispose.
Thus, in your case, without a host and without the ability to use CloseAndFlush
, you'd need to prevent your application from terminating for a few seconds, for example, by blocking the main thread with a Thread.Sleep
or wait for user input with a Console.ReadLine
, or similar...
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install serilog-extensions-logging
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page