Search Results for

    Show / Hide Table of Contents
    View Source

    Class LoggerConfigExtensions

    Provides extension methods for configuring Serilog-based logging within Umbraco applications.

    Inheritance
    object
    Namespace: Umbraco.Extensions
    Assembly: Umbraco.Infrastructure.dll
    Syntax
    public static class LoggerConfigExtensions

    Methods

    View Source

    MinimalConfiguration(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
    ILoggingConfiguration loggingConfiguration

    The logging configuration settings.

    UmbracoFileConfiguration umbracoFileConfiguration
    Returns
    Type Description
    LoggerConfiguration

    The configured Serilog.LoggerConfiguration instance.

    View Source

    MinimalConfiguration(LoggerConfiguration, IHostingEnvironment, ILoggingConfiguration, IConfiguration)

    Configures Serilog with recommended default enrichers and settings for Umbraco applications. This includes adding enrichers such as ProcessID, Thread, AppDomain, and others. It is highly recommended to retain or use this default configuration when customizing logging in your application.

    Declaration
    [Obsolete("Please use an alternative method. Scheduled for removal from Umbraco 13.")]
    public static LoggerConfiguration MinimalConfiguration(this LoggerConfiguration logConfig, IHostingEnvironment hostingEnvironment, ILoggingConfiguration loggingConfiguration, IConfiguration configuration)
    Parameters
    Type Name Description
    LoggerConfiguration logConfig

    The Serilog.LoggerConfiguration instance to configure.

    IHostingEnvironment hostingEnvironment

    The current Umbraco hosting environment.

    ILoggingConfiguration loggingConfiguration

    The logging configuration settings.

    IConfiguration configuration

    The application configuration instance.

    Returns
    Type Description
    LoggerConfiguration

    The configured Serilog.LoggerConfiguration instance with Umbraco defaults applied.

    View Source

    MinimalConfiguration(LoggerConfiguration, IHostingEnvironment, ILoggingConfiguration, IConfiguration, out 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 logging in your application.

    Declaration
    [Obsolete("Please use an alternative method. Scheduled for removal from Umbraco 13.")]
    public static LoggerConfiguration MinimalConfiguration(this LoggerConfiguration logConfig, IHostingEnvironment hostingEnvironment, ILoggingConfiguration loggingConfiguration, IConfiguration configuration, out UmbracoFileConfiguration umbFileConfiguration)
    Parameters
    Type Name Description
    LoggerConfiguration logConfig

    The Serilog.LoggerConfiguration instance to configure.

    IHostingEnvironment hostingEnvironment

    Provides information about the hosting environment.

    ILoggingConfiguration loggingConfiguration

    The logging configuration settings.

    IConfiguration configuration

    The application configuration.

    UmbracoFileConfiguration umbFileConfiguration

    When this method returns, contains the Umbraco file configuration.

    Returns
    Type Description
    LoggerConfiguration

    The configured Serilog.LoggerConfiguration instance.

    View Source

    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 Verbose (logs all events).

    int? retainedFileCount

    The number of days to retain log files. If null, all log files are kept indefinitely.

    Returns
    Type Description
    LoggerConfiguration

    The configured Serilog.LoggerConfiguration instance.

    View Source

    OutputDefaultJsonFile(LoggerConfiguration, IHostingEnvironment, ILoggingConfiguration, LogEventLevel, int?)

    Configures the logger to output a CLEF (Compact Log Event Format) JSON log file to the /App_Data/Logs/ directory.

    Declaration
    [Obsolete("Scheduled for removal from Umbraco 13.")]
    public static LoggerConfiguration OutputDefaultJsonFile(this LoggerConfiguration logConfig, IHostingEnvironment hostingEnvironment, ILoggingConfiguration loggingConfiguration, LogEventLevel minimumLevel = 0, int? retainedFileCount = null)
    Parameters
    Type Name Description
    LoggerConfiguration logConfig

    The Serilog Serilog.LoggerConfiguration to configure.

    IHostingEnvironment hostingEnvironment

    The current Umbraco hosting environment, used to resolve the log file path.

    ILoggingConfiguration loggingConfiguration

    The logging configuration settings.

    LogEventLevel minimumLevel

    The minimum Serilog.Events.LogEventLevel to log. Defaults to Verbose (logs all events).

    int? retainedFileCount

    The number of days to retain log files. If null, all log files are kept indefinitely.

    Returns
    Type Description
    LoggerConfiguration

    The configured Serilog.LoggerConfiguration instance.

    View Source

    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
    View Source

    OutputDefaultTextFile(LoggerConfiguration, IHostingEnvironment, LogEventLevel)

    Outputs a .txt format log at /App_Data/Logs/ in a format similar to the older Log4Net output.

    Declaration
    [Obsolete("Scheduled for removal from Umbraco 13.")]
    public static LoggerConfiguration OutputDefaultTextFile(this LoggerConfiguration logConfig, IHostingEnvironment hostingEnvironment, LogEventLevel minimumLevel = 0)
    Parameters
    Type Name Description
    LoggerConfiguration logConfig

    The Serilog LoggerConfiguration to configure.

    IHostingEnvironment hostingEnvironment

    The hosting environment used to resolve the log file path.

    LogEventLevel minimumLevel

    The minimum log level to write to the text file; default is Verbose (logs all events).

    Returns
    Type Description
    LoggerConfiguration

    The updated LoggerConfiguration.

    View Source

    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.

    • View Source
    In this article
    Back to top Copyright © 2016-present Umbraco
    Generated by DocFX