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. |
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. |
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. |