How do you handle configuring multiple logging configurations in code?

1,144 views
Skip to first unread message

Matthew Wilton

unread,
Apr 12, 2015, 10:24:40 PM4/12/15
to ser...@googlegroups.com
Hi

I'd like to find out how people configure multiple log configurations in code for different environments, e.g. dev vs. production, especially in cases where there are multiple production environments that require different settings. Is anyone able to share their experience and some examples of how they do this?

Previously I have configured different environments in the application's .config file, but I am now looking at using the Elasticsearch sink and this cannot be configured via appSettings.

Thanks


Nicholas Blumhardt

unread,
Apr 13, 2015, 5:05:57 PM4/13/15
to Matthew Wilton, ser...@googlegroups.com
Hi Matthew,

I think this is just an oversight in the newly-published second version of this sink. If you can weigh in here: https://github.com/serilog/serilog/issues/425 the folks supporting that sink will be able to weigh in.

Cheers!
Nick

--
You received this message because you are subscribed to the Google Groups "Serilog" group.
To unsubscribe from this group and stop receiving emails from it, send an email to serilog+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Matthew Wilton

unread,
Apr 13, 2015, 5:16:31 PM4/13/15
to ser...@googlegroups.com, matthew...@gmail.com
Thanks Nick. I will weigh in there (and will even often to create a pull request for your simple suggestion).

I am still curious if and how people configure different environments in code. I understand that it's not a straight forward question to answer, so will appreciate anyone who can share any info.

Ian Yates

unread,
Apr 13, 2015, 11:00:33 PM4/13/15
to ser...@googlegroups.com, matthew...@gmail.com
I have our web.config gettings its appsettings from another .config file in the same folder.  We don't use the Serilog appsettings library simply because we already have a bunch of custom flags (disable/enable various modules, auth schemes, etc) so Serilog settings were just another set of flags.

Doing it this way means I can upgrade a client's installation by just blowing away their entire website folder, except for their custom .config file.  Our web.config has <appsettings file="otherConfigfile.config">...  See this article for more info: http://www.codeproject.com/Articles/8818/Using-the-File-attribute-of-the-appSettings-elemen

The settings we have include (I've given the descriptive names/purposes)

Customer installation name     - this is part of every log's context.  It helps to differentiate between multiple installations on the same IIS box.  Of course you can use Seq auth tokens for this too.
Default minimum logging level
Use Seq sink?
Address of Seq server
Auth token for Seq server
Use console sink?
Use rolling file sink?
Rolling file name

These settings are read and configured when first setting up the global logger (which is then put into a Windsor container).

We haven't had a need to go crazy with different logging levels for different components in the application although I could see some merit in that down the line (NLog's walkthrough really encourages this sort of thing).

Is that the sort of stuff you were after?

Matthew Wilton

unread,
Apr 13, 2015, 11:25:16 PM4/13/15
to ser...@googlegroups.com, matthew...@gmail.com
Awesome, thanks Ian! That is the sort of info I am looking for. I wanted to find out what design and methods other people are using for configuring Serilog.

Ian Yates

unread,
Apr 14, 2015, 9:16:09 PM4/14/15
to ser...@googlegroups.com, matthew...@gmail.com
Happy to actually be of help to someone on here :)
Reply all
Reply to author
Forward
0 new messages