serilog

How do I get a serilog enricher to work with dependency injection while keeping it on startup?

左心房为你撑大大i 提交于 2021-02-07 06:09:17
问题 There is an answer here: How do I pass a dependency to a Serilog Enricher? which explains you can pass an instance in. However to do that I would need to move my logger setup after my dependency injection code has ran (in the startup.cs ) This means that startup errors won't be logged because the logger won't be ready yet. Is there a way to somehow configure serilog to run in my Main() method, but also enrich data with a DI item? The DI item has further dependencies (mainly on database

Is it possible to display Serilog log in the program's GUI?

江枫思渺然 提交于 2021-02-06 15:31:29
问题 With the logging system Serilog is it possible to display the log in a text box, or a list view or some other GUI control; what is the mechanism to get it there? 回答1: Serilog provides the ILogEventSink extension point for this. You can use it to add log events to a list, or render them onto a TextWriter somewhere. There are varying degrees of sophistication possible, depending on your needs. This one (based on ConsoleSink ) should get you going: class InMemorySink : ILogEventSink { readonly

Is it possible to display Serilog log in the program's GUI?

最后都变了- 提交于 2021-02-06 15:31:17
问题 With the logging system Serilog is it possible to display the log in a text box, or a list view or some other GUI control; what is the mechanism to get it there? 回答1: Serilog provides the ILogEventSink extension point for this. You can use it to add log events to a list, or render them onto a TextWriter somewhere. There are varying degrees of sophistication possible, depending on your needs. This one (based on ConsoleSink ) should get you going: class InMemorySink : ILogEventSink { readonly

Is it possible to display Serilog log in the program's GUI?

巧了我就是萌 提交于 2021-02-06 15:29:38
问题 With the logging system Serilog is it possible to display the log in a text box, or a list view or some other GUI control; what is the mechanism to get it there? 回答1: Serilog provides the ILogEventSink extension point for this. You can use it to add log events to a list, or render them onto a TextWriter somewhere. There are varying degrees of sophistication possible, depending on your needs. This one (based on ConsoleSink ) should get you going: class InMemorySink : ILogEventSink { readonly

Is it possible to display Serilog log in the program's GUI?

家住魔仙堡 提交于 2021-02-06 15:29:33
问题 With the logging system Serilog is it possible to display the log in a text box, or a list view or some other GUI control; what is the mechanism to get it there? 回答1: Serilog provides the ILogEventSink extension point for this. You can use it to add log events to a list, or render them onto a TextWriter somewhere. There are varying degrees of sophistication possible, depending on your needs. This one (based on ConsoleSink ) should get you going: class InMemorySink : ILogEventSink { readonly

Serilog - how to customize date in rolling file name?

点点圈 提交于 2021-01-29 17:11:34
问题 In Serilog, you can easily enable rolling log files: Log.Logger = new LoggerConfiguration() .WriteTo.File("log-.txt", rollingInterval: RollingInterval.Day) .CreateLogger(); This will create a new log file every day in the following format: log-20200214.txt log-20200215.txt log-20200216.txt My question: is it possible to customize where the date is placed in the file name, and to customize how the date is formatted? e.g. I want the file names to look like this: 2020-02-14-log.txt 2020-02-15

Serilog clobbering over multiple logs?

不羁的心 提交于 2021-01-29 05:17:13
问题 This is too bizarre for words. I have 2 completely separate programs, both of which use Serilog, like: Log.Logger = new LoggerConfiguration () .MinimumLevel.Debug () .Filter.ByExcluding (e => e.MessageTemplate.Text.Contains ("Could not find file")) .WriteTo.File ("testA-.log", rollingInterval: RollingInterval.Day, retainedFileCountLimit: 1, outputTemplate: template) .CreateLogger (); The 2nd program logs to "testB-.log". Now, the bizarre part is, that when program B logs to "testB-.log"... it

Log failover with Serilog

落花浮王杯 提交于 2021-01-28 22:53:53
问题 Is it possible, using Serilog, to log to a webservice of mine and if throws an error (no internet, for instance) to log to a RollingFile. Should only log to RollingFile if WebService fails. 回答1: You can implement this yourself by creating a custom sink that wraps another new RollingFileSink(...) and only forwards events if the web service call fails. To do this you'd implement ILogEventSink or, if the web service accepts batches, create a subclass of PeriodicBatchingSink . 来源: https:/

Adding contextual properties to Serilog logging of exceptions

 ̄綄美尐妖づ 提交于 2021-01-28 21:44:15
问题 I want to dynamically add a context value to my error logging in ASP.NET MVC. However I only have this property after a login with success. Currently I have this setup at my startup.cs: Log.Logger = new LoggerConfiguration() //other Enrich settings .Enrich.WithProperty("AccountID", AccountID) .CreateLogger(); I have tried to in my solution after a exception to logging: Log.Information("Adding {AccountID}", AccountID); And: using (LogContext.PushProperty("AccountID", AccountID)) { Log

Adding contextual properties to Serilog logging of exceptions

筅森魡賤 提交于 2021-01-28 21:10:36
问题 I want to dynamically add a context value to my error logging in ASP.NET MVC. However I only have this property after a login with success. Currently I have this setup at my startup.cs: Log.Logger = new LoggerConfiguration() //other Enrich settings .Enrich.WithProperty("AccountID", AccountID) .CreateLogger(); I have tried to in my solution after a exception to logging: Log.Information("Adding {AccountID}", AccountID); And: using (LogContext.PushProperty("AccountID", AccountID)) { Log