/// <summary> /// Create a new Loupe Sink for Serilog that will manage the Loupe session directly. /// </summary> /// <param name="configuration">The configuration for the sink</param> /// <param name="formatProvider">Optional. A format provider.</param> /// <remarks>This constructor will create a sink to use the current Loupe session which should be /// independently managed within the application. It's recommended to use the /// <see cref="LoupeExtensions.Loupe"/> extension method instead of directly creating this sink.</remarks> public LoupeSink(LoupeConfiguration configuration, IFormatProvider formatProvider = null) { _configuration = configuration; _formatProvider = formatProvider; if (string.IsNullOrWhiteSpace(_configuration.CategoryPropertyName)) { _resolveCategory = e => "Serilog"; } else { _resolveCategory = e => ResolveCategoryFromLogEvent(e, _configuration.CategoryPropertyName); } if (configuration.RenderProperties) { _resolveDetails = ResolveDetailsFromLogEvent; } }
/// <summary> /// Write Serilog Events to Loupe /// </summary> /// <param name="loggerConfiguration">The Serilog configuration</param> /// <param name="categoryPropertyName">The name of the property in the event to use as the Loupe Category</param> /// <param name="includeCallLocation">True to include class and method info for each log message</param> /// <param name="renderProperties">True to render the Serilog event properties in the Loupe message details</param> /// <param name="restrictedToMinimumLevel">The minimum level of events to pass to Loupe</param> /// <param name="formatProvider">Optional. A custom formatter for rendering events.</param> /// <returns>the updated Serilog configuration</returns> public static LoggerConfiguration Loupe( this LoggerSinkConfiguration loggerConfiguration, string categoryPropertyName = null, bool includeCallLocation = true, bool renderProperties = true, LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum, IFormatProvider formatProvider = null) { var config = new LoupeConfiguration { CategoryPropertyName = categoryPropertyName, EndSessionOnClose = false, //we don't own the Loupe agent. IncludeCallLocation = includeCallLocation, RenderProperties = renderProperties, RestrictedToMinimumLevel = restrictedToMinimumLevel }; return(loggerConfiguration.Sink(new LoupeSink(config, formatProvider))); }
/// <summary> /// Create a new Loupe Sink for Serilog that will manage the Loupe session directly. /// </summary> /// <param name="loupeConfiguration">The configuration for the Loupe Agent itself</param> /// <param name="sinkConfiguration">The configuration for the sink</param> /// <param name="formatProvider">Optional. A format provider.</param> /// <remarks>This constructor will start a Loupe session with the provided configuration and /// will end the Loupe session when the sink is disposed. It's recommended to use the /// <see cref="LoupeExtensions.Loupe"/> extension method instead of directly creating this sink.</remarks> public LoupeSink(AgentConfiguration loupeConfiguration, LoupeConfiguration sinkConfiguration, IFormatProvider formatProvider = null) : this(sinkConfiguration, formatProvider) { Log.StartSession(loupeConfiguration); }
/// <summary> /// Create a new Loupe Sink for Serilog that will manage the Loupe session directly. /// </summary> /// <param name="loupeConfiguration">The configuration for the Loupe Agent itself</param> /// <param name="sinkConfiguration">The configuration for the sink</param> /// <param name="formatProvider">Optional. A format provider.</param> /// <remarks>This constructor will start a Loupe session with the provided configuration and /// will end the Loupe session when the sink is disposed. It's recommended to use the /// <see cref="LoupeExtensions.Loupe"/> extension method instead of directly creating this sink.</remarks> public LoupeSink(AgentConfiguration loupeConfiguration, LoupeConfiguration sinkConfiguration, IFormatProvider formatProvider = null) : this(sinkConfiguration, formatProvider) { Log.Initialize(loupeConfiguration); }