Seq Documentation and Support

Welcome to the Seq documentation hub. You'll find comprehensive guides and documentation to help you start working with Seq as quickly as possible, as well as support if you get stuck. Let's jump right in!

Get Started    


Ask A Question

Dynamic Logging Levels + Web.config transformations -- is this approach correct?

Hi all, My goal is to: * Have a base Serilog config (Web.config) which uses no API key and has a debug level of information. * Have transforms (e.g. Web.Stage.config) which may / may not supply & API key, and which defer to Seq on logging levels (but also supply a default in the config). My current base `Web.config` reads: ``` <!-- Serilog / Seq Logging Configuration --> <add key="serilog:minimum-level" value="Debug" /> <!-- Logging Levels: Verbose, Debug, Information, Warning, Error --> <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.apiKey" value="" /> ``` My example test transformation includes the API key & server (redacted): ``` <add key="serilog:minimum-level" value="Information" xdt:Locator="Match(key)" xdt:Transform="SetAttributes(value)" /> <add key="serilog:write-to:Seq.serverUrl" value="http://[Redacted]:5341" xdt:Locator="Match(key)" xdt:Transform="SetAttributes(value)" /> <add key="serilog:write-to:Seq.apiKey" value="[Redacted]" xdt:Locator="Match(key)" xdt:Transform="SetAttributes(value)" /> ``` In an Autofac module, I have: ``` private ILogger WireUpSerilog() { var levelSwitch = new LoggingLevelSwitch(); var envName = ConfigurationManager.AppSettings["Environment"]; var logger = new LoggerConfiguration() .ReadFrom.AppSettings() .MinimumLevel.ControlledBy(levelSwitch) .Enrich.WithProperty("Environment", envName) .Enrich.WithEnvironmentUserName() .Enrich.WithMachineName() .CreateLogger(); Log.Logger = logger; return logger; } ``` which is then wired up as: ``` builder.Register(c => WireUpSerilog()).As<ILogger>().InstancePerLifetimeScope(); ``` Is this sufficient to enable dynamic logging levels via API keys? Or is there anything I'm missing here? Do I need to specify the use of LoggingLevelSwitch in the config itself? Just making sure.

Posted by Sean Killeen 4 years ago