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

Allow configuration of multiple seq servers #42

Open
schnitty opened this issue Apr 20, 2020 · 10 comments
Open

Allow configuration of multiple seq servers #42

schnitty opened this issue Apr 20, 2020 · 10 comments

Comments

@schnitty
Copy link

If I want to write to two Seq servers I can do this in code by:

.WriteTo.Seq("http://localhost:5341")
.WriteTo.Seq("http://otherhost:5341")
.CreateLogger();

I'm not sure how I can do this in appSettings
If I configure like so:

<add key="serilog:using:Seq" value="Serilog.Sinks.Seq" />
<add key="serilog:write-to:Seq.serverUrl" value="http://localhost:5341" />
<add key="serilog:write-to:Seq.serverUrl" value="http://otherhost:5341"/>

It ends up only sending logs to otherhost as the key is the same so it overwrites the first one.
Is there away to make these settings unique so that it ends up sending logs to both servers?

@nblumhardt
Copy link
Member

Hi! It's been a little while since I used this syntax, but this should be what you need:

<add key="serilog:using:FirstSeq" value="Serilog.Sinks.Seq" />
<add key="serilog:write-to:FirstSeq.serverUrl" value="http://localhost:5341" />
<add key="serilog:using:OtherSeq" value="Serilog.Sinks.Seq" />
<add key="serilog:write-to:OtherSeq.serverUrl" value="http://otherhost:5341"/>

@schnitty
Copy link
Author

Thanks, that looks like it should work but it doesnt :(

@nblumhardt
Copy link
Member

Sorry, that's me misremembering the features of Serilog.Settings.AppSettings. I think this is a limitation of the syntax. It's possible to use prefixes to work around it, i.e.:

<add key="serilog:using:Seq" value="Serilog.Sinks.Seq" />
<add key="serilog:write-to:Seq.serverUrl" value="http://localhost:5341" />
<add key="serilog-2:using:Seq" value="Serilog.Sinks.Seq" />
<add key="serilog-2:write-to:Seq.serverUrl" value="http://otherhost:5341"/>

but this requires an additional ReadFrom.AppSettings("serilog-2") in the application.

I'll give this a bit more thought, it'd be nice to support this cleanly.

@schnitty
Copy link
Author

Thanks for your help, I appreciate it.
Unfortunately I can't get the workaround you listed to work either. It only picks up the first Sink, doesn't add the second "serilog-2" even when I add ReadFrom.AppSettings("serilog-2") in code

The intent is to have the server addresses configurable so my fallback is to create my own appsettings that contain the server addresses and then just reference them from code.

I'd prefer the all config option but if not workable my fallback plan will at least achieve the outcome of a web administrator being able to change the servers in config without having to rebuild the code.

@nblumhardt
Copy link
Member

I don't suppose there's any chance your test harness is missing a Log.CloseAndFlush() call? That often presents as missing events from one or more loggers. (If you're not using the static Log class, then this corresponds with disposing the root Logger.)

@schnitty
Copy link
Author

schnitty commented Apr 22, 2020

Good for raising it, that has certainly tripped me up in the past but I don't think that is the issue.
When I create the logger and inspect its properties in the debugger it has only one Seq sink in its collection instead of two. So it doesn't seem to be picking up the separate non standard configuration.

web.config

...
    <add key="serilog:using:Seq" value="Serilog.Sinks.Seq" />
    <add key="serilog:write-to:Seq.serverUrl" value="http://localhost:5341" />
    <add key="serilog2:using:Seq" value="Serilog.Sinks.Seq" />
    <add key="serilog2:write-to:Seq.serverUrl" value="http://otherhost:5341"/>
...

In debugger, I would expect two rows for Seq sinks, I only see one
Debugger

@schnitty
Copy link
Author

I'm also using Autofac for DI and have registered the logger according to
https://github.com/nblumhardt/autofac-serilog-integration

@nblumhardt
Copy link
Member

Sorry, my mistake again - just checked the role of settingPrefix - it's prepended in addition to serilog:, so the keys should be:

    <add key="serilog:using:Seq" value="Serilog.Sinks.Seq" />
    <add key="serilog:write-to:Seq.serverUrl" value="http://localhost:5341" />
    <add key="serilog2:serilog:using:Seq" value="Serilog.Sinks.Seq" />
    <add key="serilog2:serilog:write-to:Seq.serverUrl" value="http://otherhost:5341"/>

@schnitty
Copy link
Author

Awesome, that works. Thanks so much.
Out of curiority where is the documenation that specified that? I haven't been able to find any.

@nblumhardt
Copy link
Member

Great 👍 - it's mentioned in the intellisense docs for the parameter, I found it in: https://github.com/serilog/serilog-settings-appsettings/blob/dev/src/Serilog.Settings.AppSettings/AppSettingsLoggerConfigurationExtensions.cs#L62

Cheers,
Nick

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