/// <summary>Logs an error event to the default <see cref="Logger"/>.</summary> /// <param name="logger">The logger.</param> /// <param name="exception">The exception that has to be logged.</param> /// <returns>The id of the logged event or null in one of the following reasons: /// The event hasn't been logged, because of the current /// <see cref="LoggingProviderBase.Threshold">Threshold</see> level; /// Returning an id is not supported by the current implementation; /// The event has been logged to a fallback provider, because of an error in the current implementation. /// </returns> /// <exception cref="ArgumentNullException">Thrown when the supplied <paramref name="exception"/> is /// a null reference (Nothing in VB) or the supplied <paramref name="logger"/> is a null reference. /// </exception> /// <exception cref="Exception">Thrown when the logging provider failed to log the event. The /// exact type of exception thrown depends on the actual provider implementation. See documentation /// of the <see cref="LoggingProviderBase.LogInternal">LogInternal</see> method of the used logging /// provider for more information.</exception> public static object Log(this ILogger logger, Exception exception) { LoggingHelper.ValideLoggerIsNotNull(logger); LoggingHelper.ValidateExceptionIsNotNull(exception); string message = LoggingHelper.GetExceptionMessageOrExceptionType(exception); LogEntry entry = new LogEntry(LoggingEventType.Error, message, null, exception); return(logger.Log(entry)); }
/// <summary>Logs an error event to the wrapped <see cref="Logger"/>.</summary> /// <param name="logger">The logger.</param> /// <param name="exception">The exception that has to be logged.</param> /// <param name="source">A source where the event occurred.</param> /// <returns>The id of the logged event or null in one of the following reasons: /// The event hasn't been logged, because of the current /// <see cref="LoggingProviderBase.Threshold">Threshold</see> level; /// Returning an id is not supported by the current implementation; /// The event has been logged to a fallback provider, because of an error in the current implementation. /// </returns> /// <exception cref="ArgumentNullException"> /// Thrown when the supplied <paramref name="exception"/>, /// the <paramref name="source"/> or <paramref name="logger"/> are null references (Nothing in VB). /// </exception> /// <exception cref="Exception">Thrown when the logging provider failed to log the event. The /// exact type of exception thrown depends on the actual provider implementation. See documentation /// of the <see cref="LoggingProviderBase.LogInternal">LogInternal</see> method of the used logging /// provider for more information.</exception> public static object Log(this ILogger logger, Exception exception, MethodBase source) { LoggingHelper.ValideLoggerIsNotNull(logger); LoggingHelper.ValidateExceptionIsNotNull(exception); LoggingHelper.ValidateSourceIsNotNull(source); string message = LoggingHelper.GetExceptionMessageOrExceptionType(exception); string methodName = LoggingHelper.BuildMethodName(source); LogEntry entry = new LogEntry(LoggingEventType.Error, message, methodName, exception); return(logger.Log(entry)); }