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

Restrict to level #45

Closed
josephwoodward opened this issue Feb 14, 2017 · 3 comments
Closed

Restrict to level #45

josephwoodward opened this issue Feb 14, 2017 · 3 comments

Comments

@josephwoodward
Copy link

Hi,

What's the best approach to restricting a log to a certain level? I see RollingFile has a restrictToMinimumLevel parameter, but if I wish to restrict the log data to only errors then I can't see this being an option. I recall there being a filter API which seems like it would be the next best thing.

Alternatively could you see much value in having a restrictToLevel property available on the method?

@nblumhardt
Copy link
Member

Hi Joseph, this should work for you:

Log.Logger = new LoggerConfiguration()
    .WriteTo.Logger(lc => lc
        .Filter.ByIncludingOnly(evt => evt.Level == LogEventLevel.Error)
        .WriteTo.RollingFile("errors.txt"))
    .WriteTo.Logger(lc => lc
        .Filter.ByIncludingOnly(evt => evt.Level == LogEventLevel.Warning)
        .WriteTo.RollingFile("warnings.txt"))
    .CreateLogger();

How's that fit? Cheers!

@josephwoodward
Copy link
Author

Nice, that should do it! On a side note, do you have any up for grabs issues that are suitable for someone new to Serilog? I'd love to contribute if I could, Serilog is an awesome library!

@nblumhardt
Copy link
Member

Great, thanks for the interest!

There are a lot of repositories spread around the organisation with a few up-for-grabs item in there.

If you're interested in Linux and Win 10, I think serilog-archive/serilog-sinks-literate#9 would be a fun one?

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

2 participants