LoggerExtensions Class¶
ILogger extension methods for common scenarios.
- Namespace
Microsoft.Extensions.Logging
- Assemblies
- Microsoft.Extensions.Logging.Abstractions
Methods¶
-
BeginScope
(Microsoft.Extensions.Logging.ILogger, System.String, System.Object[])¶ Formats the message and creates a scope.
Arguments: - logger (Microsoft.Extensions.Logging.ILogger) – The
Microsoft.Extensions.Logging.ILogger
to create the scope in. - messageFormat (System.String) – Format string of the scope message.
- args (System.Object<System.Object>[]) – An object array that contains zero or more objects to format.
Return type: System.IDisposable
Returns: A disposable scope object. Can be null.
public static IDisposable BeginScope(this ILogger logger, string messageFormat, params object[] args)
- logger (Microsoft.Extensions.Logging.ILogger) – The
-
LogCritical
(Microsoft.Extensions.Logging.ILogger, Microsoft.Extensions.Logging.EventId, System.Exception, System.String, System.Object[])¶ Formats and writes a critical log message.
Arguments: - logger (Microsoft.Extensions.Logging.ILogger) – The
Microsoft.Extensions.Logging.ILogger
to write to. - eventId (Microsoft.Extensions.Logging.EventId) – The event id associated with the log.
- exception (System.Exception) – The exception to log.
- message (System.String) – Format string of the log message.
- args (System.Object<System.Object>[]) – An object array that contains zero or more objects to format.
public static void LogCritical(this ILogger logger, EventId eventId, Exception exception, string message, params object[] args)
- logger (Microsoft.Extensions.Logging.ILogger) – The
-
LogCritical
(Microsoft.Extensions.Logging.ILogger, Microsoft.Extensions.Logging.EventId, System.String, System.Object[]) Formats and writes a critical log message.
Arguments: - logger (Microsoft.Extensions.Logging.ILogger) – The
Microsoft.Extensions.Logging.ILogger
to write to. - eventId (Microsoft.Extensions.Logging.EventId) – The event id associated with the log.
- message (System.String) – Format string of the log message.
- args (System.Object<System.Object>[]) – An object array that contains zero or more objects to format.
public static void LogCritical(this ILogger logger, EventId eventId, string message, params object[] args)
- logger (Microsoft.Extensions.Logging.ILogger) – The
-
LogCritical
(Microsoft.Extensions.Logging.ILogger, System.String, System.Object[]) Formats and writes a critical log message.
Arguments: - logger (Microsoft.Extensions.Logging.ILogger) – The
Microsoft.Extensions.Logging.ILogger
to write to. - message (System.String) – Format string of the log message.
- args (System.Object<System.Object>[]) – An object array that contains zero or more objects to format.
public static void LogCritical(this ILogger logger, string message, params object[] args)
- logger (Microsoft.Extensions.Logging.ILogger) – The
-
LogDebug
(Microsoft.Extensions.Logging.ILogger, Microsoft.Extensions.Logging.EventId, System.Exception, System.String, System.Object[])¶ Formats and writes a debug log message.
Arguments: - logger (Microsoft.Extensions.Logging.ILogger) – The
Microsoft.Extensions.Logging.ILogger
to write to. - eventId (Microsoft.Extensions.Logging.EventId) – The event id associated with the log.
- exception (System.Exception) – The exception to log.
- message (System.String) – Format string of the log message.
- args (System.Object<System.Object>[]) – An object array that contains zero or more objects to format.
public static void LogDebug(this ILogger logger, EventId eventId, Exception exception, string message, params object[] args)
- logger (Microsoft.Extensions.Logging.ILogger) – The
-
LogDebug
(Microsoft.Extensions.Logging.ILogger, Microsoft.Extensions.Logging.EventId, System.String, System.Object[]) Formats and writes a debug log message.
Arguments: - logger (Microsoft.Extensions.Logging.ILogger) – The
Microsoft.Extensions.Logging.ILogger
to write to. - eventId (Microsoft.Extensions.Logging.EventId) – The event id associated with the log.
- message (System.String) – Format string of the log message.
- args (System.Object<System.Object>[]) – An object array that contains zero or more objects to format.
public static void LogDebug(this ILogger logger, EventId eventId, string message, params object[] args)
- logger (Microsoft.Extensions.Logging.ILogger) – The
-
LogDebug
(Microsoft.Extensions.Logging.ILogger, System.String, System.Object[]) Formats and writes a debug log message.
Arguments: - logger (Microsoft.Extensions.Logging.ILogger) – The
Microsoft.Extensions.Logging.ILogger
to write to. - message (System.String) – Format string of the log message.
- args (System.Object<System.Object>[]) – An object array that contains zero or more objects to format.
public static void LogDebug(this ILogger logger, string message, params object[] args)
- logger (Microsoft.Extensions.Logging.ILogger) – The
-
LogError
(Microsoft.Extensions.Logging.ILogger, Microsoft.Extensions.Logging.EventId, System.Exception, System.String, System.Object[])¶ Formats and writes an error log message.
Arguments: - logger (Microsoft.Extensions.Logging.ILogger) – The
Microsoft.Extensions.Logging.ILogger
to write to. - eventId (Microsoft.Extensions.Logging.EventId) – The event id associated with the log.
- exception (System.Exception) – The exception to log.
- message (System.String) – Format string of the log message.
- args (System.Object<System.Object>[]) – An object array that contains zero or more objects to format.
public static void LogError(this ILogger logger, EventId eventId, Exception exception, string message, params object[] args)
- logger (Microsoft.Extensions.Logging.ILogger) – The
-
LogError
(Microsoft.Extensions.Logging.ILogger, Microsoft.Extensions.Logging.EventId, System.String, System.Object[]) Formats and writes an error log message.
Arguments: - logger (Microsoft.Extensions.Logging.ILogger) – The
Microsoft.Extensions.Logging.ILogger
to write to. - eventId (Microsoft.Extensions.Logging.EventId) – The event id associated with the log.
- message (System.String) – Format string of the log message.
- args (System.Object<System.Object>[]) – An object array that contains zero or more objects to format.
public static void LogError(this ILogger logger, EventId eventId, string message, params object[] args)
- logger (Microsoft.Extensions.Logging.ILogger) – The
-
LogError
(Microsoft.Extensions.Logging.ILogger, System.String, System.Object[]) Formats and writes an error log message.
Arguments: - logger (Microsoft.Extensions.Logging.ILogger) – The
Microsoft.Extensions.Logging.ILogger
to write to. - message (System.String) – Format string of the log message.
- args (System.Object<System.Object>[]) – An object array that contains zero or more objects to format.
public static void LogError(this ILogger logger, string message, params object[] args)
- logger (Microsoft.Extensions.Logging.ILogger) – The
-
LogInformation
(Microsoft.Extensions.Logging.ILogger, Microsoft.Extensions.Logging.EventId, System.Exception, System.String, System.Object[])¶ Formats and writes an informational log message.
Arguments: - logger (Microsoft.Extensions.Logging.ILogger) – The
Microsoft.Extensions.Logging.ILogger
to write to. - eventId (Microsoft.Extensions.Logging.EventId) – The event id associated with the log.
- exception (System.Exception) – The exception to log.
- message (System.String) – Format string of the log message.
- args (System.Object<System.Object>[]) – An object array that contains zero or more objects to format.
public static void LogInformation(this ILogger logger, EventId eventId, Exception exception, string message, params object[] args)
- logger (Microsoft.Extensions.Logging.ILogger) – The
-
LogInformation
(Microsoft.Extensions.Logging.ILogger, Microsoft.Extensions.Logging.EventId, System.String, System.Object[]) Formats and writes an informational log message.
Arguments: - logger (Microsoft.Extensions.Logging.ILogger) – The
Microsoft.Extensions.Logging.ILogger
to write to. - eventId (Microsoft.Extensions.Logging.EventId) – The event id associated with the log.
- message (System.String) – Format string of the log message.
- args (System.Object<System.Object>[]) – An object array that contains zero or more objects to format.
public static void LogInformation(this ILogger logger, EventId eventId, string message, params object[] args)
- logger (Microsoft.Extensions.Logging.ILogger) – The
-
LogInformation
(Microsoft.Extensions.Logging.ILogger, System.String, System.Object[]) Formats and writes an informational log message.
Arguments: - logger (Microsoft.Extensions.Logging.ILogger) – The
Microsoft.Extensions.Logging.ILogger
to write to. - message (System.String) – Format string of the log message.
- args (System.Object<System.Object>[]) – An object array that contains zero or more objects to format.
public static void LogInformation(this ILogger logger, string message, params object[] args)
- logger (Microsoft.Extensions.Logging.ILogger) – The
-
LogTrace
(Microsoft.Extensions.Logging.ILogger, Microsoft.Extensions.Logging.EventId, System.Exception, System.String, System.Object[])¶ Formats and writes a trace log message.
Arguments: - logger (Microsoft.Extensions.Logging.ILogger) – The
Microsoft.Extensions.Logging.ILogger
to write to. - eventId (Microsoft.Extensions.Logging.EventId) – The event id associated with the log.
- exception (System.Exception) – The exception to log.
- message (System.String) – Format string of the log message.
- args (System.Object<System.Object>[]) – An object array that contains zero or more objects to format.
public static void LogTrace(this ILogger logger, EventId eventId, Exception exception, string message, params object[] args)
- logger (Microsoft.Extensions.Logging.ILogger) – The
-
LogTrace
(Microsoft.Extensions.Logging.ILogger, Microsoft.Extensions.Logging.EventId, System.String, System.Object[]) Formats and writes a trace log message.
Arguments: - logger (Microsoft.Extensions.Logging.ILogger) – The
Microsoft.Extensions.Logging.ILogger
to write to. - eventId (Microsoft.Extensions.Logging.EventId) – The event id associated with the log.
- message (System.String) – Format string of the log message.
- args (System.Object<System.Object>[]) – An object array that contains zero or more objects to format.
public static void LogTrace(this ILogger logger, EventId eventId, string message, params object[] args)
- logger (Microsoft.Extensions.Logging.ILogger) – The
-
LogTrace
(Microsoft.Extensions.Logging.ILogger, System.String, System.Object[]) Formats and writes a trace log message.
Arguments: - logger (Microsoft.Extensions.Logging.ILogger) – The
Microsoft.Extensions.Logging.ILogger
to write to. - message (System.String) – Format string of the log message.
- args (System.Object<System.Object>[]) – An object array that contains zero or more objects to format.
public static void LogTrace(this ILogger logger, string message, params object[] args)
- logger (Microsoft.Extensions.Logging.ILogger) – The
-
LogWarning
(Microsoft.Extensions.Logging.ILogger, Microsoft.Extensions.Logging.EventId, System.Exception, System.String, System.Object[])¶ Formats and writes a warning log message.
Arguments: - logger (Microsoft.Extensions.Logging.ILogger) – The
Microsoft.Extensions.Logging.ILogger
to write to. - eventId (Microsoft.Extensions.Logging.EventId) – The event id associated with the log.
- exception (System.Exception) – The exception to log.
- message (System.String) – Format string of the log message.
- args (System.Object<System.Object>[]) – An object array that contains zero or more objects to format.
public static void LogWarning(this ILogger logger, EventId eventId, Exception exception, string message, params object[] args)
- logger (Microsoft.Extensions.Logging.ILogger) – The
-
LogWarning
(Microsoft.Extensions.Logging.ILogger, Microsoft.Extensions.Logging.EventId, System.String, System.Object[]) Formats and writes a warning log message.
Arguments: - logger (Microsoft.Extensions.Logging.ILogger) – The
Microsoft.Extensions.Logging.ILogger
to write to. - eventId (Microsoft.Extensions.Logging.EventId) – The event id associated with the log.
- message (System.String) – Format string of the log message.
- args (System.Object<System.Object>[]) – An object array that contains zero or more objects to format.
public static void LogWarning(this ILogger logger, EventId eventId, string message, params object[] args)
- logger (Microsoft.Extensions.Logging.ILogger) – The
-
LogWarning
(Microsoft.Extensions.Logging.ILogger, System.String, System.Object[]) Formats and writes a warning log message.
Arguments: - logger (Microsoft.Extensions.Logging.ILogger) – The
Microsoft.Extensions.Logging.ILogger
to write to. - message (System.String) – Format string of the log message.
- args (System.Object<System.Object>[]) – An object array that contains zero or more objects to format.
public static void LogWarning(this ILogger logger, string message, params object[] args)
- logger (Microsoft.Extensions.Logging.ILogger) – The
-