serilog-settings-comparison
serilog-settings-comparison copied to clipboard
AuditTo:Sublogger configuration not working
Does AuditTo support the idea of a sub logger? C# seems to allow it but not json configuration.
What is the difference in functionality between the following code?
//Json config doesn't work. Error in debug diagnostics about Logger method not found.
Logger log = new LoggerConfiguration()
.MinimumLevel.Verbose()
.WriteTo.Logger(lc => lc //sublogger1
.WriteTo.Debug())
.AuditTo.Logger(lc => lc //sublogger2
.WriteTo.TestCorrelator())
.CreateLogger();
//Json works but not sure I understand the implications. Is this functionally different then above?
Logger log = new LoggerConfiguration()
.MinimumLevel.Verbose()
.WriteTo.Logger(lc => lc //sublogger1
.WriteTo.Debug())
.WriteTo.Logger(lc => lc //sublogger2
.AuditTo.TestCorrelator())
.CreateLogger();
P.S. I also have some filters that I left out for clarity but I want audit event to go to the one sink and everything else the other. (thus subloggers, right?)
Hi,
AuditTo.Logger not being supported by the JSON configuration might actually a bug. Would you mind opening it in the corresponding repo : https://github.com/serilog/serilog-settings-configuration/issues/new
What is the difference in functionality between the following code? mmm just right now I'm not 100% sure they are equivalent. Looks like a good question to post on https://gitter.im/serilog/serilog or StackOverflow :)
I also have some filters that I left out for clarity but I want audit event to go to the one sink and everything else the other. (thus subloggers, right?)
that seems about right, yes, you can also refer to https://github.com/serilog/serilog/issues/1170#issue-327834952 , which had this example that seems to match what you are trying to do :
Log.Logger = new LoggerConfiguration()
.AuditTo.Logger(cfg => cfg
// only "audit" events will go through here
.Filter.ByIncludingOnly(evt => evt.Properties.ContainsKey("AuditEvent"))
.AuditTo.File(/*snip*/))
.WriteTo.Logger(cfg => cfg
// only "non audit events" will go through here
.Filter.ByExcludingevt => evt.Properties.ContainsKey("AuditEvent"))
.WriteTo.File(/**/))
// this applies to all
.Enrich.WithComputerName()
Posted issue here: https://github.com/serilog/serilog-settings-configuration/issues/199
thanks.
Above url looks ok, but the hyperlink is not. Should be: https://github.com/serilog/serilog-settings-configuration/issues/199