Beispiel #1
0
        public void PropertyEnrichmentIsApplied()
        {
            var configuration = new LoggerConfiguration();
            var settings      = new NameValueCollection
            {
                { "serilog:enrich:with-property:App", "Test" }
            };

            PrefixedAppSettingsReader.ConfigureLogger(configuration, settings);

            LogEvent evt = null;
            var      log = configuration.WriteTo.Sink(new DelegatingSink(e => evt = e)).CreateLogger();

            log.Information("Has a test property");

            Assert.IsNotNull(evt);
            Assert.AreEqual("Test", evt.Properties["App"].LiteralValue());
        }
Beispiel #2
0
        public void EnvironmentVariableExpansionIsApplied()
        {
            var configuration = new LoggerConfiguration();
            var settings      = new NameValueCollection
            {
                { "serilog:enrich:with-property:Path", "%PATH%" }
            };

            PrefixedAppSettingsReader.ConfigureLogger(configuration, settings);

            LogEvent evt = null;
            var      log = configuration.WriteTo.Sink(new DelegatingSink(e => evt = e)).CreateLogger();

            log.Information("Has a Path property with value expanded from the environment variable");

            Assert.IsNotNull(evt);
            Assert.AreNotEqual("%PATH%", evt.Properties["Path"].LiteralValue());
        }
 /// <summary>
 /// Reads the &lt;appSettings&gt; element of App.config or Web.config, searching for for keys
 /// that look like: <code>serilog:*</code>, which are used to configure
 /// the logger. To add a sink, use a key like <code>serilog:write-to:File.path</code> for
 /// each parameter to the sink's configuration method. To add an additional assembly
 /// containing sinkds, use <code>serilog:using</code>. To set the level use
 /// <code>serilog:minimum-level</code>.
 /// </summary>
 /// <param name="loggerConfiguration">The logger configuration to apply configuration to.</param>
 /// <returns>An object allowing configuration to continue.</returns>
 public static LoggerConfiguration ReadAppSettings(this LoggerConfiguration loggerConfiguration)
 {
     PrefixedAppSettingsReader.ConfigureLogger(loggerConfiguration);
     return(loggerConfiguration);
 }