Show / Hide Table of Contents

    Method AddSerilog

    AddSerilog(IServiceCollection)

    Adds logging services to the specified Microsoft.Extensions.DependencyInjection.IServiceCollection and registers the Serilog logging provider using the static Serilog.Log logger, which will be disposed with the logger factory.
    Declaration
    public static IServiceCollection AddSerilog(this IServiceCollection services)
    Parameters
    Type Name Description
    Microsoft.Extensions.DependencyInjection.IServiceCollection services This Microsoft.Extensions.DependencyInjection.IServiceCollection to add services to.
    Returns
    Type Description
    Microsoft.Extensions.DependencyInjection.IServiceCollection This Microsoft.Extensions.DependencyInjection.IServiceCollection instance.
    Remarks

    On .NET Standard 1.6 and lower, either no Microsoft.Extensions.Logging.ILoggerFactory or an instantiated singleton must be registered yet. Otherwise, it is not possible to add Serilog to the factory.

    On .NET Standard 2.0 and newer, the logging builder is used to register the Serilog provider.

    AddSerilog(IServiceCollection, ILogger)

    Adds logging services to the specified Microsoft.Extensions.DependencyInjection.IServiceCollection and registers the Serilog logging provider using the provided logger.
    Declaration
    public static IServiceCollection AddSerilog(this IServiceCollection services, ILogger serilogLogger)
    Parameters
    Type Name Description
    Microsoft.Extensions.DependencyInjection.IServiceCollection services This Microsoft.Extensions.DependencyInjection.IServiceCollection to add services to.
    Serilog.ILogger serilogLogger The Serilog.ILogger to use. If null, the static Serilog.Log logger is used instead, which will be disposed with the logger factory.
    Returns
    Type Description
    Microsoft.Extensions.DependencyInjection.IServiceCollection This Microsoft.Extensions.DependencyInjection.IServiceCollection instance.
    Remarks

    On .NET Standard 1.6 and lower, either no Microsoft.Extensions.Logging.ILoggerFactory or an instantiated singleton must be registered yet. Otherwise, it is not possible to add Serilog to the factory.

    On .NET Standard 2.0 and newer, the logging builder is used to register the Serilog provider.

    AddSerilog(IServiceCollection, ILogger, Action<ILoggingBuilder>)

    Adds logging services to the specified Microsoft.Extensions.DependencyInjection.IServiceCollection and registers the Serilog logging provider using the provided logger.
    Declaration
    public static IServiceCollection AddSerilog(this IServiceCollection services, ILogger serilogLogger, Action<ILoggingBuilder> configure)
    Parameters
    Type Name Description
    Microsoft.Extensions.DependencyInjection.IServiceCollection services This Microsoft.Extensions.DependencyInjection.IServiceCollection to add services to.
    Serilog.ILogger serilogLogger The Serilog.ILogger to use. If null, the static Serilog.Log logger is used instead, which will be disposed with the logger factory.
    System.Action<Microsoft.Extensions.Logging.ILoggingBuilder> configure The Microsoft.Extensions.Logging.ILoggingBuilder configuration delegate.
    Returns
    Type Description
    Microsoft.Extensions.DependencyInjection.IServiceCollection This Microsoft.Extensions.DependencyInjection.IServiceCollection instance.

    AddSerilog(IServiceCollection, Action<LoggerConfiguration>)

    Adds logging services to the specified Microsoft.Extensions.DependencyInjection.IServiceCollection that use the static Serilog.Log Serilog logger which is configured via the provided delegate. The static Serilog logger will be automatically disposed with the logger factory service.
    Declaration
    public static IServiceCollection AddSerilog(this IServiceCollection services, Action<LoggerConfiguration> configure)
    Parameters
    Type Name Description
    Microsoft.Extensions.DependencyInjection.IServiceCollection services This Microsoft.Extensions.DependencyInjection.IServiceCollection to add services to.
    System.Action<Serilog.LoggerConfiguration> configure The Serilog.LoggerConfiguration configuration delegate.
    Returns
    Type Description
    Microsoft.Extensions.DependencyInjection.IServiceCollection This Microsoft.Extensions.DependencyInjection.IServiceCollection instance.

    AddSerilog(IServiceCollection, Boolean, Action<LoggerConfiguration>)

    Adds logging services to the specified Microsoft.Extensions.DependencyInjection.IServiceCollection that use the Serilog logger which is configured via the provided delegate. The Serilog logger will be automatically disposed with the logger factory service.
    Declaration
    public static IServiceCollection AddSerilog(this IServiceCollection services, bool global, Action<LoggerConfiguration> configure)
    Parameters
    Type Name Description
    Microsoft.Extensions.DependencyInjection.IServiceCollection services This Microsoft.Extensions.DependencyInjection.IServiceCollection to add services to.
    Boolean global If set to true, the configured logger will be assigned to the global static Serilog.Log. Otherwise, the configured logger will only be used by the logging service pipeline.
    System.Action<Serilog.LoggerConfiguration> configure The Serilog.LoggerConfiguration configuration delegate.
    Returns
    Type Description
    Microsoft.Extensions.DependencyInjection.IServiceCollection This Microsoft.Extensions.DependencyInjection.IServiceCollection instance.
    Back to top Copyright © 2017-2018, xplo.re IT Services, Michael Maier. All rights reserved.