Class LoggerExtensions
Class LoggerExtensions.
Inherited Members
Namespace: AWS.Lambda.Powertools.Logging
Assembly: AWS.Lambda.Powertools.Logging.dll
Syntax
public static class LoggerExtensions
Methods
Log(ILogger, LogLevel, Exception)
Formats and writes a log message at the specified log level.
Declaration
public static void Log(this ILogger logger, LogLevel logLevel, Exception exception)
Parameters
Type | Name | Description |
---|---|---|
ILogger | logger | The ILogger to write to. |
LogLevel | logLevel | Entry will be written on this level. |
Exception | exception | The exception to log. |
Examples
logger.Log(LogLevel.Information, exception)
Log(ILogger, LogLevel, object)
Formats and writes a log message as JSON at the specified log level.
Declaration
public static void Log(this ILogger logger, LogLevel logLevel, object message)
Parameters
Type | Name | Description |
---|---|---|
ILogger | logger | The ILogger to write to. |
LogLevel | logLevel | Entry will be written on this level. |
object | message | The object to be serialized as JSON. |
Examples
logger.Log(LogLevel.Information, new {User = user, Address = address})
LogCritical(ILogger, Exception)
Formats and writes an critical log message.
Declaration
public static void LogCritical(this ILogger logger, Exception exception)
Parameters
Type | Name | Description |
---|---|---|
ILogger | logger | The ILogger to write to. |
Exception | exception | The exception to log. |
Examples
logger.LogCritical(exception)
LogCritical(ILogger, object)
Formats and writes a critical log message as JSON.
Declaration
public static void LogCritical(this ILogger logger, object message)
Parameters
Type | Name | Description |
---|---|---|
ILogger | logger | The ILogger to write to. |
object | message | The object to be serialized as JSON. |
Examples
logger.LogCritical(new {User = user, Address = address})
LogCritical<T>(ILogger, T, EventId, Exception, string, params object[])
Formats and writes a critical log message.
Declaration
public static void LogCritical<T>(this ILogger logger, T extraKeys, EventId eventId, Exception exception, string message, params object[] args) where T : class
Parameters
Type | Name | Description |
---|---|---|
ILogger | logger | The ILogger to write to. |
T | extraKeys | Additional keys will be appended to the log entry. |
EventId | eventId | The event id associated with the log. |
Exception | exception | The exception to log. |
string | message | Format string of the log message in message template format. Example: |
object[] | args | An object array that contains zero or more objects to format. |
Type Parameters
Name | Description |
---|---|
T |
Examples
logger.LogCritical(extraKeys, 0, exception, "Error while processing request from {Address}", address)
LogCritical<T>(ILogger, T, EventId, string, params object[])
Formats and writes a critical log message.
Declaration
public static void LogCritical<T>(this ILogger logger, T extraKeys, EventId eventId, string message, params object[] args) where T : class
Parameters
Type | Name | Description |
---|---|---|
ILogger | logger | The ILogger to write to. |
T | extraKeys | Additional keys will be appended to the log entry. |
EventId | eventId | The event id associated with the log. |
string | message | Format string of the log message in message template format. Example: |
object[] | args | An object array that contains zero or more objects to format. |
Type Parameters
Name | Description |
---|---|
T |
Examples
logger.LogCritical(extraKeys, 0, "Processing request from {Address}", address)
LogCritical<T>(ILogger, T, Exception, string, params object[])
Formats and writes a critical log message.
Declaration
public static void LogCritical<T>(this ILogger logger, T extraKeys, Exception exception, string message, params object[] args) where T : class
Parameters
Type | Name | Description |
---|---|---|
ILogger | logger | The ILogger to write to. |
T | extraKeys | Additional keys will be appended to the log entry. |
Exception | exception | The exception to log. |
string | message | Format string of the log message in message template format. Example: |
object[] | args | An object array that contains zero or more objects to format. |
Type Parameters
Name | Description |
---|---|
T |
Examples
logger.LogCritical(extraKeys, exception, "Error while processing request from {Address}", address)
LogCritical<T>(ILogger, T, string, params object[])
Formats and writes a critical log message.
Declaration
public static void LogCritical<T>(this ILogger logger, T extraKeys, string message, params object[] args) where T : class
Parameters
Type | Name | Description |
---|---|---|
ILogger | logger | The ILogger to write to. |
T | extraKeys | Additional keys will be appended to the log entry. |
string | message | Format string of the log message in message template format. Example: |
object[] | args | An object array that contains zero or more objects to format. |
Type Parameters
Name | Description |
---|---|
T |
Examples
logger.LogCritical(extraKeys, "Processing request from {Address}", address)
LogDebug(ILogger, Exception)
Formats and writes an debug log message.
Declaration
public static void LogDebug(this ILogger logger, Exception exception)
Parameters
Type | Name | Description |
---|---|---|
ILogger | logger | The ILogger to write to. |
Exception | exception | The exception to log. |
Examples
logger.LogDebug(exception)
LogDebug(ILogger, object)
Formats and writes a debug log message as JSON.
Declaration
public static void LogDebug(this ILogger logger, object message)
Parameters
Type | Name | Description |
---|---|---|
ILogger | logger | The ILogger to write to. |
object | message | The object to be serialized as JSON. |
Examples
logger.LogDebug(new {User = user, Address = address})
LogDebug<T>(ILogger, T, EventId, Exception, string, params object[])
Formats and writes a debug log message.
Declaration
public static void LogDebug<T>(this ILogger logger, T extraKeys, EventId eventId, Exception exception, string message, params object[] args) where T : class
Parameters
Type | Name | Description |
---|---|---|
ILogger | logger | The ILogger to write to. |
T | extraKeys | Additional keys will be appended to the log entry. |
EventId | eventId | The event id associated with the log. |
Exception | exception | The exception to log. |
string | message | Format string of the log message in message template format. Example: |
object[] | args | An object array that contains zero or more objects to format. |
Type Parameters
Name | Description |
---|---|
T |
Examples
logger.LogDebug(extraKeys, 0, exception, "Error while processing request from {Address}", address)
LogDebug<T>(ILogger, T, EventId, string, params object[])
Formats and writes a debug log message.
Declaration
public static void LogDebug<T>(this ILogger logger, T extraKeys, EventId eventId, string message, params object[] args) where T : class
Parameters
Type | Name | Description |
---|---|---|
ILogger | logger | The ILogger to write to. |
T | extraKeys | Additional keys will be appended to the log entry. |
EventId | eventId | The event id associated with the log. |
string | message | Format string of the log message in message template format. Example: |
object[] | args | An object array that contains zero or more objects to format. |
Type Parameters
Name | Description |
---|---|
T |
Examples
logger.LogDebug(extraKeys, 0, "Processing request from {Address}", address)
LogDebug<T>(ILogger, T, Exception, string, params object[])
Formats and writes a debug log message.
Declaration
public static void LogDebug<T>(this ILogger logger, T extraKeys, Exception exception, string message, params object[] args) where T : class
Parameters
Type | Name | Description |
---|---|---|
ILogger | logger | The ILogger to write to. |
T | extraKeys | Additional keys will be appended to the log entry. |
Exception | exception | The exception to log. |
string | message | Format string of the log message in message template format. Example: |
object[] | args | An object array that contains zero or more objects to format. |
Type Parameters
Name | Description |
---|---|
T |
Examples
logger.LogDebug(extraKeys, exception, "Error while processing request from {Address}", address)
LogDebug<T>(ILogger, T, string, params object[])
Formats and writes a debug log message.
Declaration
public static void LogDebug<T>(this ILogger logger, T extraKeys, string message, params object[] args) where T : class
Parameters
Type | Name | Description |
---|---|---|
ILogger | logger | The ILogger to write to. |
T | extraKeys | Additional keys will be appended to the log entry. |
string | message | Format string of the log message in message template format. Example: |
object[] | args | An object array that contains zero or more objects to format. |
Type Parameters
Name | Description |
---|---|
T |
Examples
logger.LogDebug(extraKeys, "Processing request from {Address}", address)
LogError(ILogger, Exception)
Formats and writes an error log message.
Declaration
public static void LogError(this ILogger logger, Exception exception)
Parameters
Type | Name | Description |
---|---|---|
ILogger | logger | The ILogger to write to. |
Exception | exception | The exception to log. |
Examples
logger.LogError(exception)
LogError(ILogger, object)
Formats and writes a error log message as JSON.
Declaration
public static void LogError(this ILogger logger, object message)
Parameters
Type | Name | Description |
---|---|---|
ILogger | logger | The ILogger to write to. |
object | message | The object to be serialized as JSON. |
Examples
logger.LogCritical(new {User = user, Address = address})
LogError<T>(ILogger, T, EventId, Exception, string, params object[])
Formats and writes an error log message.
Declaration
public static void LogError<T>(this ILogger logger, T extraKeys, EventId eventId, Exception exception, string message, params object[] args) where T : class
Parameters
Type | Name | Description |
---|---|---|
ILogger | logger | The ILogger to write to. |
T | extraKeys | Additional keys will be appended to the log entry. |
EventId | eventId | The event id associated with the log. |
Exception | exception | The exception to log. |
string | message | Format string of the log message in message template format. Example: |
object[] | args | An object array that contains zero or more objects to format. |
Type Parameters
Name | Description |
---|---|
T |
Examples
logger.LogError(extraKeys, 0, exception, "Error while processing request from {Address}", address)
LogError<T>(ILogger, T, EventId, string, params object[])
Formats and writes an error log message.
Declaration
public static void LogError<T>(this ILogger logger, T extraKeys, EventId eventId, string message, params object[] args) where T : class
Parameters
Type | Name | Description |
---|---|---|
ILogger | logger | The ILogger to write to. |
T | extraKeys | Additional keys will be appended to the log entry. |
EventId | eventId | The event id associated with the log. |
string | message | Format string of the log message in message template format. Example: |
object[] | args | An object array that contains zero or more objects to format. |
Type Parameters
Name | Description |
---|---|
T |
Examples
logger.LogError(extraKeys, 0, "Processing request from {Address}", address)
LogError<T>(ILogger, T, Exception, string, params object[])
Formats and writes an error log message.
Declaration
public static void LogError<T>(this ILogger logger, T extraKeys, Exception exception, string message, params object[] args) where T : class
Parameters
Type | Name | Description |
---|---|---|
ILogger | logger | The ILogger to write to. |
T | extraKeys | Additional keys will be appended to the log entry. |
Exception | exception | The exception to log. |
string | message | Format string of the log message in message template format. Example: |
object[] | args | An object array that contains zero or more objects to format. |
Type Parameters
Name | Description |
---|---|
T |
Examples
logger.LogError(extraKeys, exception, "Error while processing request from {Address}", address)
LogError<T>(ILogger, T, string, params object[])
Formats and writes an error log message.
Declaration
public static void LogError<T>(this ILogger logger, T extraKeys, string message, params object[] args) where T : class
Parameters
Type | Name | Description |
---|---|---|
ILogger | logger | The ILogger to write to. |
T | extraKeys | Additional keys will be appended to the log entry. |
string | message | Format string of the log message in message template format. Example: |
object[] | args | An object array that contains zero or more objects to format. |
Type Parameters
Name | Description |
---|---|
T |
Examples
logger.LogError(extraKeys, "Processing request from {Address}", address)
LogInformation(ILogger, Exception)
Formats and writes an information log message.
Declaration
public static void LogInformation(this ILogger logger, Exception exception)
Parameters
Type | Name | Description |
---|---|---|
ILogger | logger | The ILogger to write to. |
Exception | exception | The exception to log. |
Examples
logger.LogInformation(exception)
LogInformation(ILogger, object)
Formats and writes an information log message as JSON.
Declaration
public static void LogInformation(this ILogger logger, object message)
Parameters
Type | Name | Description |
---|---|---|
ILogger | logger | The ILogger to write to. |
object | message | The object to be serialized as JSON. |
Examples
logger.LogInformation(new {User = user, Address = address})
LogInformation<T>(ILogger, T, EventId, Exception, string, params object[])
Formats and writes an informational log message.
Declaration
public static void LogInformation<T>(this ILogger logger, T extraKeys, EventId eventId, Exception exception, string message, params object[] args) where T : class
Parameters
Type | Name | Description |
---|---|---|
ILogger | logger | The ILogger to write to. |
T | extraKeys | Additional keys will be appended to the log entry. |
EventId | eventId | The event id associated with the log. |
Exception | exception | The exception to log. |
string | message | Format string of the log message in message template format. Example: |
object[] | args | An object array that contains zero or more objects to format. |
Type Parameters
Name | Description |
---|---|
T |
Examples
logger.LogInformation(extraKeys, 0, exception, "Error while processing request from {Address}", address)
LogInformation<T>(ILogger, T, EventId, string, params object[])
Formats and writes an informational log message.
Declaration
public static void LogInformation<T>(this ILogger logger, T extraKeys, EventId eventId, string message, params object[] args) where T : class
Parameters
Type | Name | Description |
---|---|---|
ILogger | logger | The ILogger to write to. |
T | extraKeys | Additional keys will be appended to the log entry. |
EventId | eventId | The event id associated with the log. |
string | message | Format string of the log message in message template format. Example: |
object[] | args | An object array that contains zero or more objects to format. |
Type Parameters
Name | Description |
---|---|
T |
Examples
logger.LogInformation(extraKeys, 0, "Processing request from {Address}", address)
LogInformation<T>(ILogger, T, Exception, string, params object[])
Formats and writes an informational log message.
Declaration
public static void LogInformation<T>(this ILogger logger, T extraKeys, Exception exception, string message, params object[] args) where T : class
Parameters
Type | Name | Description |
---|---|---|
ILogger | logger | The ILogger to write to. |
T | extraKeys | Additional keys will be appended to the log entry. |
Exception | exception | The exception to log. |
string | message | Format string of the log message in message template format. Example: |
object[] | args | An object array that contains zero or more objects to format. |
Type Parameters
Name | Description |
---|---|
T |
Examples
logger.LogInformation(extraKeys, exception, "Error while processing request from {Address}", address)
LogInformation<T>(ILogger, T, string, params object[])
Formats and writes an informational log message.
Declaration
public static void LogInformation<T>(this ILogger logger, T extraKeys, string message, params object[] args) where T : class
Parameters
Type | Name | Description |
---|---|---|
ILogger | logger | The ILogger to write to. |
T | extraKeys | Additional keys will be appended to the log entry. |
string | message | Format string of the log message in message template format. Example: |
object[] | args | An object array that contains zero or more objects to format. |
Type Parameters
Name | Description |
---|---|
T |
Examples
logger.LogInformation(extraKeys, "Processing request from {Address}", address)
LogTrace(ILogger, Exception)
Formats and writes an trace log message.
Declaration
public static void LogTrace(this ILogger logger, Exception exception)
Parameters
Type | Name | Description |
---|---|---|
ILogger | logger | The ILogger to write to. |
Exception | exception | The exception to log. |
Examples
logger.LogTrace(exception)
LogTrace(ILogger, object)
Formats and writes a trace log message as JSON.
Declaration
public static void LogTrace(this ILogger logger, object message)
Parameters
Type | Name | Description |
---|---|---|
ILogger | logger | The ILogger to write to. |
object | message | The object to be serialized as JSON. |
Examples
logger.LogTrace(new {User = user, Address = address})
LogTrace<T>(ILogger, T, EventId, Exception, string, params object[])
Formats and writes a trace log message.
Declaration
public static void LogTrace<T>(this ILogger logger, T extraKeys, EventId eventId, Exception exception, string message, params object[] args) where T : class
Parameters
Type | Name | Description |
---|---|---|
ILogger | logger | The ILogger to write to. |
T | extraKeys | Additional keys will be appended to the log entry. |
EventId | eventId | The event id associated with the log. |
Exception | exception | The exception to log. |
string | message | Format string of the log message in message template format. Example: |
object[] | args | An object array that contains zero or more objects to format. |
Type Parameters
Name | Description |
---|---|
T |
Examples
logger.LogTrace(extraKeys, 0, exception, "Error while processing request from {Address}", address)
LogTrace<T>(ILogger, T, EventId, string, params object[])
Formats and writes a trace log message.
Declaration
public static void LogTrace<T>(this ILogger logger, T extraKeys, EventId eventId, string message, params object[] args) where T : class
Parameters
Type | Name | Description |
---|---|---|
ILogger | logger | The ILogger to write to. |
T | extraKeys | Additional keys will be appended to the log entry. |
EventId | eventId | The event id associated with the log. |
string | message | Format string of the log message in message template format. Example: |
object[] | args | An object array that contains zero or more objects to format. |
Type Parameters
Name | Description |
---|---|
T |
Examples
logger.LogTrace(extraKeys, 0, "Processing request from {Address}", address)
LogTrace<T>(ILogger, T, Exception, string, params object[])
Formats and writes a trace log message.
Declaration
public static void LogTrace<T>(this ILogger logger, T extraKeys, Exception exception, string message, params object[] args) where T : class
Parameters
Type | Name | Description |
---|---|---|
ILogger | logger | The ILogger to write to. |
T | extraKeys | Additional keys will be appended to the log entry. |
Exception | exception | The exception to log. |
string | message | Format string of the log message in message template format. Example: |
object[] | args | An object array that contains zero or more objects to format. |
Type Parameters
Name | Description |
---|---|
T |
Examples
logger.LogTrace(extraKeys, exception, "Error while processing request from {Address}", address)
LogTrace<T>(ILogger, T, string, params object[])
Formats and writes a trace log message.
Declaration
public static void LogTrace<T>(this ILogger logger, T extraKeys, string message, params object[] args) where T : class
Parameters
Type | Name | Description |
---|---|---|
ILogger | logger | The ILogger to write to. |
T | extraKeys | Additional keys will be appended to the log entry. |
string | message | Format string of the log message in message template format. Example: |
object[] | args | An object array that contains zero or more objects to format. |
Type Parameters
Name | Description |
---|---|
T |
Examples
logger.LogTrace(extraKeys, "Processing request from {Address}", address)
LogWarning(ILogger, Exception)
Formats and writes an warning log message.
Declaration
public static void LogWarning(this ILogger logger, Exception exception)
Parameters
Type | Name | Description |
---|---|---|
ILogger | logger | The ILogger to write to. |
Exception | exception | The exception to log. |
Examples
logger.LogWarning(exception)
LogWarning(ILogger, object)
Formats and writes a warning log message as JSON.
Declaration
public static void LogWarning(this ILogger logger, object message)
Parameters
Type | Name | Description |
---|---|---|
ILogger | logger | The ILogger to write to. |
object | message | The object to be serialized as JSON. |
Examples
logger.LogWarning(new {User = user, Address = address})
LogWarning<T>(ILogger, T, EventId, Exception, string, params object[])
Formats and writes a warning log message.
Declaration
public static void LogWarning<T>(this ILogger logger, T extraKeys, EventId eventId, Exception exception, string message, params object[] args) where T : class
Parameters
Type | Name | Description |
---|---|---|
ILogger | logger | The ILogger to write to. |
T | extraKeys | Additional keys will be appended to the log entry. |
EventId | eventId | The event id associated with the log. |
Exception | exception | The exception to log. |
string | message | Format string of the log message in message template format. Example: |
object[] | args | An object array that contains zero or more objects to format. |
Type Parameters
Name | Description |
---|---|
T |
Examples
logger.LogWarning(extraKeys, 0, exception, "Error while processing request from {Address}", address)
LogWarning<T>(ILogger, T, EventId, string, params object[])
Formats and writes a warning log message.
Declaration
public static void LogWarning<T>(this ILogger logger, T extraKeys, EventId eventId, string message, params object[] args) where T : class
Parameters
Type | Name | Description |
---|---|---|
ILogger | logger | The ILogger to write to. |
T | extraKeys | Additional keys will be appended to the log entry. |
EventId | eventId | The event id associated with the log. |
string | message | Format string of the log message in message template format. Example: |
object[] | args | An object array that contains zero or more objects to format. |
Type Parameters
Name | Description |
---|---|
T |
Examples
logger.LogWarning(extraKeys, 0, "Processing request from {Address}", address)
LogWarning<T>(ILogger, T, Exception, string, params object[])
Formats and writes a warning log message.
Declaration
public static void LogWarning<T>(this ILogger logger, T extraKeys, Exception exception, string message, params object[] args) where T : class
Parameters
Type | Name | Description |
---|---|---|
ILogger | logger | The ILogger to write to. |
T | extraKeys | Additional keys will be appended to the log entry. |
Exception | exception | The exception to log. |
string | message | Format string of the log message in message template format. Example: |
object[] | args | An object array that contains zero or more objects to format. |
Type Parameters
Name | Description |
---|---|
T |
Examples
logger.LogWarning(extraKeys, exception, "Error while processing request from {Address}", address)
LogWarning<T>(ILogger, T, string, params object[])
Formats and writes a warning log message.
Declaration
public static void LogWarning<T>(this ILogger logger, T extraKeys, string message, params object[] args) where T : class
Parameters
Type | Name | Description |
---|---|---|
ILogger | logger | The ILogger to write to. |
T | extraKeys | Additional keys will be appended to the log entry. |
string | message | Format string of the log message in message template format. Example: |
object[] | args | An object array that contains zero or more objects to format. |
Type Parameters
Name | Description |
---|---|
T |
Examples
logger.LogWarning(extraKeys, "Processing request from {Address}", address)
Log<T>(ILogger, LogLevel, T, EventId, Exception, string, params object[])
Formats and writes a log message at the specified log level.
Declaration
public static void Log<T>(this ILogger logger, LogLevel logLevel, T extraKeys, EventId eventId, Exception exception, string message, params object[] args) where T : class
Parameters
Type | Name | Description |
---|---|---|
ILogger | logger | The ILogger to write to. |
LogLevel | logLevel | Entry will be written on this level. |
T | extraKeys | Additional keys will be appended to the log entry. |
EventId | eventId | The event id associated with the log. |
Exception | exception | The exception to log. |
string | message | Format string of the log message in message template format. Example: |
object[] | args | An object array that contains zero or more objects to format. |
Type Parameters
Name | Description |
---|---|
T |
Examples
logger.Log(LogLevel.Information, extraKeys, 0, exception, "Error while processing request from {Address}", address)
Log<T>(ILogger, LogLevel, T, EventId, string, params object[])
Formats and writes a log message at the specified log level.
Declaration
public static void Log<T>(this ILogger logger, LogLevel logLevel, T extraKeys, EventId eventId, string message, params object[] args) where T : class
Parameters
Type | Name | Description |
---|---|---|
ILogger | logger | The ILogger to write to. |
LogLevel | logLevel | Entry will be written on this level. |
T | extraKeys | Additional keys will be appended to the log entry. |
EventId | eventId | The event id associated with the log. |
string | message | Format string of the log message in message template format. Example: |
object[] | args | An object array that contains zero or more objects to format. |
Type Parameters
Name | Description |
---|---|
T |
Examples
logger.Log(LogLevel.Information, extraKeys, 0, "Processing request from {Address}", address)
Log<T>(ILogger, LogLevel, T, Exception, string, params object[])
Formats and writes a log message at the specified log level.
Declaration
public static void Log<T>(this ILogger logger, LogLevel logLevel, T extraKeys, Exception exception, string message, params object[] args) where T : class
Parameters
Type | Name | Description |
---|---|---|
ILogger | logger | The ILogger to write to. |
LogLevel | logLevel | Entry will be written on this level. |
T | extraKeys | Additional keys will be appended to the log entry. |
Exception | exception | The exception to log. |
string | message | Format string of the log message in message template format. Example: |
object[] | args | An object array that contains zero or more objects to format. |
Type Parameters
Name | Description |
---|---|
T |
Examples
logger.Log(LogLevel.Information, extraKeys, exception, "Error while processing request from {Address}", address)
Log<T>(ILogger, LogLevel, T, string, params object[])
Formats and writes a log message at the specified log level.
Declaration
public static void Log<T>(this ILogger logger, LogLevel logLevel, T extraKeys, string message, params object[] args) where T : class
Parameters
Type | Name | Description |
---|---|---|
ILogger | logger | The ILogger to write to. |
LogLevel | logLevel | Entry will be written on this level. |
T | extraKeys | Additional keys will be appended to the log entry. |
string | message | Format string of the log message in message template format. Example: |
object[] | args | An object array that contains zero or more objects to format. |
Type Parameters
Name | Description |
---|---|
T |
Examples
logger.Log(LogLevel.Information, extraKeys, "Processing request from {Address}", address)