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()); }
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()); }
public void ValuesConvertToEnumMembers() { var result = (LogEventLevel)PrefixedAppSettingsReader.ConvertToType("Information", typeof(LogEventLevel)); Assert.AreEqual(LogEventLevel.Information, result); }
public void EmptyStringValuesConvertToNullIfTargetIsNullable() { var result = (int?)PrefixedAppSettingsReader.ConvertToType("", typeof(int?)); Assert.That(result == null); }
public void ConvertibleValuesConvertToTIfTargetIsNullable() { var result = (int?)PrefixedAppSettingsReader.ConvertToType("3", typeof(int?)); Assert.That(result == 3); }
/// <summary> /// Reads the <appSettings> 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); }