serilog-settings-comparison icon indicating copy to clipboard operation
serilog-settings-comparison copied to clipboard

AuditTo:Sublogger configuration not working

Open leejeffr opened this issue 6 years ago • 3 comments

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?)

leejeffr avatar Oct 22 '19 03:10 leejeffr

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()

tsimbalar avatar Oct 22 '19 06:10 tsimbalar

Posted issue here: https://github.com/serilog/serilog-settings-configuration/issues/199

thanks.

leejeffr avatar Oct 22 '19 16:10 leejeffr

Above url looks ok, but the hyperlink is not. Should be: https://github.com/serilog/serilog-settings-configuration/issues/199

AroglDarthu avatar Jun 30 '20 15:06 AroglDarthu