Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AuditTo:Sublogger configuration not working #2

Open
leejeffr opened this issue Oct 22, 2019 · 3 comments
Open

AuditTo:Sublogger configuration not working #2

leejeffr opened this issue Oct 22, 2019 · 3 comments

Comments

@leejeffr
Copy link

leejeffr commented Oct 22, 2019

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

@tsimbalar
Copy link
Owner

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 serilog/serilog#1170 (comment) , 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()

@leejeffr
Copy link
Author

@AroglDarthu
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants