Class LoggerConfigExtensions
Provides extension methods for configuring Serilog-based logging within Umbraco applications.
Inheritance
Namespace: Umbraco.Extensions
Assembly: Umbraco.Infrastructure.dll
Syntax
public static class LoggerConfigExtensions
Methods
View SourceMinimalConfiguration(LoggerConfiguration, IHostEnvironment, ILoggingConfiguration, UmbracoFileConfiguration)
Configures Serilog with recommended default enrichers and settings, such as adding ProcessID, Thread, and AppDomain information. It is highly recommended to retain this default configuration when customizing your own logging setup.
Declaration
public static LoggerConfiguration MinimalConfiguration(this LoggerConfiguration logConfig, IHostEnvironment hostEnvironment, ILoggingConfiguration loggingConfiguration, UmbracoFileConfiguration umbracoFileConfiguration)
Parameters
| Type | Name | Description |
|---|---|---|
| LoggerConfiguration | logConfig | The Serilog.LoggerConfiguration instance to configure. |
| IHostEnvironment | hostEnvironment | The Umbraco hosting environment. |
| ILoggingConfiguration | loggingConfiguration | The logging configuration settings. |
| UmbracoFileConfiguration | umbracoFileConfiguration | The Umbraco file configuration settings. |
Returns
| Type | Description |
|---|---|
| LoggerConfiguration | The configured Serilog.LoggerConfiguration instance. |
OutputDefaultJsonFile(LoggerConfiguration, IHostEnvironment, LoggingSettings, LogEventLevel, int?)
Configures the logger to output logs in CLEF (Compact Log Event Format) JSON format to the /App_Data/Logs/ directory.
Declaration
public static LoggerConfiguration OutputDefaultJsonFile(this LoggerConfiguration logConfig, IHostEnvironment hostEnvironment, LoggingSettings loggingSettings, LogEventLevel minimumLevel = 0, int? retainedFileCount = null)
Parameters
| Type | Name | Description |
|---|---|---|
| LoggerConfiguration | logConfig | The Serilog Serilog.LoggerConfiguration to configure. |
| IHostEnvironment | hostEnvironment | The hosting environment used to resolve the log file path. |
| LoggingSettings | loggingSettings | The logging configuration settings. |
| LogEventLevel | minimumLevel | The minimum log event level to write to the JSON file. Default is |
| int? | retainedFileCount | The number of days to retain log files. If |
Returns
| Type | Description |
|---|---|
| LoggerConfiguration | The configured Serilog.LoggerConfiguration instance. |
OutputDefaultTextFile(LoggerConfiguration, IHostEnvironment, LoggingSettings, LogEventLevel)
Outputs a .txt format log at /App_Data/Logs/
Declaration
public static LoggerConfiguration OutputDefaultTextFile(this LoggerConfiguration logConfig, IHostEnvironment hostEnvironment, LoggingSettings loggingSettings, LogEventLevel minimumLevel = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| LoggerConfiguration | logConfig | A Serilog LoggerConfiguration |
| IHostEnvironment | hostEnvironment | |
| LoggingSettings | loggingSettings | |
| LogEventLevel | minimumLevel | The log level you wish the JSON file to collect - default is Verbose (highest) |
Returns
| Type | Description |
|---|---|
| LoggerConfiguration |
UmbracoFile(LoggerSinkConfiguration, string, ITextFormatter?, LogEventLevel, LoggingLevelSwitch?, long?, TimeSpan?, RollingInterval, bool, int?, Encoding?)
Configures a Serilog file sink for logging with Umbraco-specific defaults.
Declaration
public static LoggerConfiguration UmbracoFile(this LoggerSinkConfiguration configuration, string path, ITextFormatter? formatter = null, LogEventLevel restrictedToMinimumLevel = 0, LoggingLevelSwitch? levelSwitch = null, long? fileSizeLimitBytes = 1073741824, TimeSpan? flushToDiskInterval = null, RollingInterval rollingInterval = 3, bool rollOnFileSizeLimit = false, int? retainedFileCountLimit = 31, Encoding? encoding = null)
Parameters
| Type | Name | Description |
|---|---|---|
| LoggerSinkConfiguration | configuration | The logger sink configuration to extend. |
| string | path | The file path where log entries will be written. |
| ITextFormatter | formatter | An optional text formatter for log entries. If not specified, a compact JSON formatter is used. |
| LogEventLevel | restrictedToMinimumLevel | The minimum log event level required to write to the sink. Defaults to Verbose. |
| LoggingLevelSwitch | levelSwitch | An optional level switch to dynamically control the minimum log level. |
| long? | fileSizeLimitBytes | The maximum size, in bytes, for a single log file before rolling. Defaults to 1 GB. |
| TimeSpan? | flushToDiskInterval | The interval at which log entries are flushed to disk. If null, the default Serilog behavior is used. |
| RollingInterval | rollingInterval | The interval at which log files are rolled (e.g., daily). Defaults to daily rolling. |
| bool | rollOnFileSizeLimit | If true, rolls the log file when the size limit is reached. |
| int? | retainedFileCountLimit | The maximum number of log files to retain. Older files are deleted. Defaults to 31. |
| Encoding | encoding | The text encoding to use for the log file. If null, UTF-8 is used. |
Returns
| Type | Description |
|---|---|
| LoggerConfiguration | The logger configuration with the file sink applied. |
Remarks
Used in configuration files. If this method is renamed or moved to another assembly, the configuration file must also be updated accordingly.