From e66a2c5b2f871ac573439d9b1d1df0a2ad5f6447 Mon Sep 17 00:00:00 2001 From: Nicholas Blumhardt Date: Thu, 28 Jul 2022 09:04:41 +1000 Subject: [PATCH] Bring Log.* methods exception nullability into line with ILogger (#1707) --- src/Serilog/Log.cs | 70 +++++++++++++++++++++++----------------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/src/Serilog/Log.cs b/src/Serilog/Log.cs index 38dbc5b77..cb75e5159 100644 --- a/src/Serilog/Log.cs +++ b/src/Serilog/Log.cs @@ -187,7 +187,7 @@ public static void Write(LogEventLevel level, string messageTemplate, params obj /// Exception related to the event. /// Message template describing the event. [MessageTemplateFormatMethod("messageTemplate")] - public static void Write(LogEventLevel level, Exception exception, string messageTemplate) + public static void Write(LogEventLevel level, Exception? exception, string messageTemplate) { Logger.Write(level, exception, messageTemplate); } @@ -200,7 +200,7 @@ public static void Write(LogEventLevel level, Exception exception, string messag /// Message template describing the event. /// Object positionally formatted into the message template. [MessageTemplateFormatMethod("messageTemplate")] - public static void Write(LogEventLevel level, Exception exception, string messageTemplate, T propertyValue) + public static void Write(LogEventLevel level, Exception? exception, string messageTemplate, T propertyValue) { Logger.Write(level, exception, messageTemplate, propertyValue); } @@ -214,7 +214,7 @@ public static void Write(LogEventLevel level, Exception exception, string mes /// Object positionally formatted into the message template. /// Object positionally formatted into the message template. [MessageTemplateFormatMethod("messageTemplate")] - public static void Write(LogEventLevel level, Exception exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1) + public static void Write(LogEventLevel level, Exception? exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1) { Logger.Write(level, exception, messageTemplate, propertyValue0, propertyValue1); } @@ -229,7 +229,7 @@ public static void Write(LogEventLevel level, Exception exception, string mes /// Object positionally formatted into the message template. /// Object positionally formatted into the message template. [MessageTemplateFormatMethod("messageTemplate")] - public static void Write(LogEventLevel level, Exception exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1, T2 propertyValue2) + public static void Write(LogEventLevel level, Exception? exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1, T2 propertyValue2) { Logger.Write(level, exception, messageTemplate, propertyValue0, propertyValue1, propertyValue2); } @@ -242,7 +242,7 @@ public static void Write(LogEventLevel level, Exception exception, string mes /// Message template describing the event. /// Objects positionally formatted into the message template. [MessageTemplateFormatMethod("messageTemplate")] - public static void Write(LogEventLevel level, Exception exception, string messageTemplate, params object?[]? propertyValues) + public static void Write(LogEventLevel level, Exception? exception, string messageTemplate, params object?[]? propertyValues) { Logger.Write(level, exception, messageTemplate, propertyValues); } @@ -336,7 +336,7 @@ public static void Verbose(string messageTemplate, params object?[]? propertyVal /// Log.Verbose(ex, "Staring into space, wondering where this comet came from."); /// [MessageTemplateFormatMethod("messageTemplate")] - public static void Verbose(Exception exception, string messageTemplate) + public static void Verbose(Exception? exception, string messageTemplate) { Write(LogEventLevel.Verbose, exception, messageTemplate); } @@ -351,7 +351,7 @@ public static void Verbose(Exception exception, string messageTemplate) /// Log.Verbose(ex, "Staring into space, wondering where this comet came from."); /// [MessageTemplateFormatMethod("messageTemplate")] - public static void Verbose(Exception exception, string messageTemplate, T propertyValue) + public static void Verbose(Exception? exception, string messageTemplate, T propertyValue) { Write(LogEventLevel.Verbose, exception, messageTemplate, propertyValue); } @@ -367,7 +367,7 @@ public static void Verbose(Exception exception, string messageTemplate, T pro /// Log.Verbose(ex, "Staring into space, wondering where this comet came from."); /// [MessageTemplateFormatMethod("messageTemplate")] - public static void Verbose(Exception exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1) + public static void Verbose(Exception? exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1) { Write(LogEventLevel.Verbose, exception, messageTemplate, propertyValue0, propertyValue1); } @@ -384,7 +384,7 @@ public static void Verbose(Exception exception, string messageTemplate, T pro /// Log.Verbose(ex, "Staring into space, wondering where this comet came from."); /// [MessageTemplateFormatMethod("messageTemplate")] - public static void Verbose(Exception exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1, T2 propertyValue2) + public static void Verbose(Exception? exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1, T2 propertyValue2) { Write(LogEventLevel.Verbose, exception, messageTemplate, propertyValue0, propertyValue1, propertyValue2); } @@ -399,7 +399,7 @@ public static void Verbose(Exception exception, string messageTemplate, T pro /// Log.Verbose(ex, "Staring into space, wondering where this comet came from."); /// [MessageTemplateFormatMethod("messageTemplate")] - public static void Verbose(Exception exception, string messageTemplate, params object?[]? propertyValues) + public static void Verbose(Exception? exception, string messageTemplate, params object?[]? propertyValues) { Logger.Verbose(exception, messageTemplate, propertyValues); } @@ -485,7 +485,7 @@ public static void Debug(string messageTemplate, params object?[]? propertyValue /// Log.Debug(ex, "Swallowing a mundane exception."); /// [MessageTemplateFormatMethod("messageTemplate")] - public static void Debug(Exception exception, string messageTemplate) + public static void Debug(Exception? exception, string messageTemplate) { Write(LogEventLevel.Debug, exception, messageTemplate); } @@ -500,7 +500,7 @@ public static void Debug(Exception exception, string messageTemplate) /// Log.Debug(ex, "Swallowing a mundane exception."); /// [MessageTemplateFormatMethod("messageTemplate")] - public static void Debug(Exception exception, string messageTemplate, T propertyValue) + public static void Debug(Exception? exception, string messageTemplate, T propertyValue) { Write(LogEventLevel.Debug, exception, messageTemplate, propertyValue); } @@ -516,7 +516,7 @@ public static void Debug(Exception exception, string messageTemplate, T prope /// Log.Debug(ex, "Swallowing a mundane exception."); /// [MessageTemplateFormatMethod("messageTemplate")] - public static void Debug(Exception exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1) + public static void Debug(Exception? exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1) { Write(LogEventLevel.Debug, exception, messageTemplate, propertyValue0, propertyValue1); } @@ -533,7 +533,7 @@ public static void Debug(Exception exception, string messageTemplate, T prope /// Log.Debug(ex, "Swallowing a mundane exception."); /// [MessageTemplateFormatMethod("messageTemplate")] - public static void Debug(Exception exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1, T2 propertyValue2) + public static void Debug(Exception? exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1, T2 propertyValue2) { Write(LogEventLevel.Debug, exception, messageTemplate, propertyValue0, propertyValue1, propertyValue2); } @@ -548,7 +548,7 @@ public static void Debug(Exception exception, string messageTemplate, T prope /// Log.Debug(ex, "Swallowing a mundane exception."); /// [MessageTemplateFormatMethod("messageTemplate")] - public static void Debug(Exception exception, string messageTemplate, params object?[]? propertyValues) + public static void Debug(Exception? exception, string messageTemplate, params object?[]? propertyValues) { Logger.Debug(exception, messageTemplate, propertyValues); } @@ -634,7 +634,7 @@ public static void Information(string messageTemplate, params object?[]? propert /// Log.Information(ex, "Processed {RecordCount} records in {TimeMS}.", records.Length, sw.ElapsedMilliseconds); /// [MessageTemplateFormatMethod("messageTemplate")] - public static void Information(Exception exception, string messageTemplate) + public static void Information(Exception? exception, string messageTemplate) { Write(LogEventLevel.Information, exception, messageTemplate); } @@ -649,7 +649,7 @@ public static void Information(Exception exception, string messageTemplate) /// Log.Information(ex, "Processed {RecordCount} records in {TimeMS}.", records.Length, sw.ElapsedMilliseconds); /// [MessageTemplateFormatMethod("messageTemplate")] - public static void Information(Exception exception, string messageTemplate, T propertyValue) + public static void Information(Exception? exception, string messageTemplate, T propertyValue) { Write(LogEventLevel.Information, exception, messageTemplate, propertyValue); } @@ -665,7 +665,7 @@ public static void Information(Exception exception, string messageTemplate, T /// Log.Information(ex, "Processed {RecordCount} records in {TimeMS}.", records.Length, sw.ElapsedMilliseconds); /// [MessageTemplateFormatMethod("messageTemplate")] - public static void Information(Exception exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1) + public static void Information(Exception? exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1) { Write(LogEventLevel.Information, exception, messageTemplate, propertyValue0, propertyValue1); } @@ -682,7 +682,7 @@ public static void Information(Exception exception, string messageTemplate, T /// Log.Information(ex, "Processed {RecordCount} records in {TimeMS}.", records.Length, sw.ElapsedMilliseconds); /// [MessageTemplateFormatMethod("messageTemplate")] - public static void Information(Exception exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1, T2 propertyValue2) + public static void Information(Exception? exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1, T2 propertyValue2) { Write(LogEventLevel.Information, exception, messageTemplate, propertyValue0, propertyValue1, propertyValue2); } @@ -697,7 +697,7 @@ public static void Information(Exception exception, string messageTemplate, T /// Log.Information(ex, "Processed {RecordCount} records in {TimeMS}.", records.Length, sw.ElapsedMilliseconds); /// [MessageTemplateFormatMethod("messageTemplate")] - public static void Information(Exception exception, string messageTemplate, params object?[]? propertyValues) + public static void Information(Exception? exception, string messageTemplate, params object?[]? propertyValues) { Logger.Information(exception, messageTemplate, propertyValues); } @@ -783,7 +783,7 @@ public static void Warning(string messageTemplate, params object?[]? propertyVal /// Log.Warning(ex, "Skipped {SkipCount} records.", skippedRecords.Length); /// [MessageTemplateFormatMethod("messageTemplate")] - public static void Warning(Exception exception, string messageTemplate) + public static void Warning(Exception? exception, string messageTemplate) { Write(LogEventLevel.Warning, exception, messageTemplate); } @@ -798,7 +798,7 @@ public static void Warning(Exception exception, string messageTemplate) /// Log.Warning(ex, "Skipped {SkipCount} records.", skippedRecords.Length); /// [MessageTemplateFormatMethod("messageTemplate")] - public static void Warning(Exception exception, string messageTemplate, T propertyValue) + public static void Warning(Exception? exception, string messageTemplate, T propertyValue) { Write(LogEventLevel.Warning, exception, messageTemplate, propertyValue); } @@ -814,7 +814,7 @@ public static void Warning(Exception exception, string messageTemplate, T pro /// Log.Warning(ex, "Skipped {SkipCount} records.", skippedRecords.Length); /// [MessageTemplateFormatMethod("messageTemplate")] - public static void Warning(Exception exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1) + public static void Warning(Exception? exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1) { Write(LogEventLevel.Warning, exception, messageTemplate, propertyValue0, propertyValue1); } @@ -831,7 +831,7 @@ public static void Warning(Exception exception, string messageTemplate, T pro /// Log.Warning(ex, "Skipped {SkipCount} records.", skippedRecords.Length); /// [MessageTemplateFormatMethod("messageTemplate")] - public static void Warning(Exception exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1, T2 propertyValue2) + public static void Warning(Exception? exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1, T2 propertyValue2) { Write(LogEventLevel.Warning, exception, messageTemplate, propertyValue0, propertyValue1, propertyValue2); } @@ -846,7 +846,7 @@ public static void Warning(Exception exception, string messageTemplate, T pro /// Log.Warning(ex, "Skipped {SkipCount} records.", skippedRecords.Length); /// [MessageTemplateFormatMethod("messageTemplate")] - public static void Warning(Exception exception, string messageTemplate, params object?[]? propertyValues) + public static void Warning(Exception? exception, string messageTemplate, params object?[]? propertyValues) { Logger.Warning(exception, messageTemplate, propertyValues); } @@ -932,7 +932,7 @@ public static void Error(string messageTemplate, params object?[]? propertyValue /// Log.Error(ex, "Failed {ErrorCount} records.", brokenRecords.Length); /// [MessageTemplateFormatMethod("messageTemplate")] - public static void Error(Exception exception, string messageTemplate) + public static void Error(Exception? exception, string messageTemplate) { Write(LogEventLevel.Error, exception, messageTemplate); } @@ -947,7 +947,7 @@ public static void Error(Exception exception, string messageTemplate) /// Log.Error(ex, "Failed {ErrorCount} records.", brokenRecords.Length); /// [MessageTemplateFormatMethod("messageTemplate")] - public static void Error(Exception exception, string messageTemplate, T propertyValue) + public static void Error(Exception? exception, string messageTemplate, T propertyValue) { Write(LogEventLevel.Error, exception, messageTemplate, propertyValue); } @@ -963,7 +963,7 @@ public static void Error(Exception exception, string messageTemplate, T prope /// Log.Error(ex, "Failed {ErrorCount} records.", brokenRecords.Length); /// [MessageTemplateFormatMethod("messageTemplate")] - public static void Error(Exception exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1) + public static void Error(Exception? exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1) { Write(LogEventLevel.Error, exception, messageTemplate, propertyValue0, propertyValue1); } @@ -980,7 +980,7 @@ public static void Error(Exception exception, string messageTemplate, T prope /// Log.Error(ex, "Failed {ErrorCount} records.", brokenRecords.Length); /// [MessageTemplateFormatMethod("messageTemplate")] - public static void Error(Exception exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1, T2 propertyValue2) + public static void Error(Exception? exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1, T2 propertyValue2) { Write(LogEventLevel.Error, exception, messageTemplate, propertyValue0, propertyValue1, propertyValue2); } @@ -995,7 +995,7 @@ public static void Error(Exception exception, string messageTemplate, T prope /// Log.Error(ex, "Failed {ErrorCount} records.", brokenRecords.Length); /// [MessageTemplateFormatMethod("messageTemplate")] - public static void Error(Exception exception, string messageTemplate, params object?[]? propertyValues) + public static void Error(Exception? exception, string messageTemplate, params object?[]? propertyValues) { Logger.Error(exception, messageTemplate, propertyValues); } @@ -1081,7 +1081,7 @@ public static void Fatal(string messageTemplate, params object?[]? propertyValue /// Log.Fatal(ex, "Process terminating."); /// [MessageTemplateFormatMethod("messageTemplate")] - public static void Fatal(Exception exception, string messageTemplate) + public static void Fatal(Exception? exception, string messageTemplate) { Write(LogEventLevel.Fatal, exception, messageTemplate); } @@ -1096,7 +1096,7 @@ public static void Fatal(Exception exception, string messageTemplate) /// Log.Fatal(ex, "Process terminating."); /// [MessageTemplateFormatMethod("messageTemplate")] - public static void Fatal(Exception exception, string messageTemplate, T propertyValue) + public static void Fatal(Exception? exception, string messageTemplate, T propertyValue) { Write(LogEventLevel.Fatal, exception, messageTemplate, propertyValue); } @@ -1112,7 +1112,7 @@ public static void Fatal(Exception exception, string messageTemplate, T prope /// Log.Fatal(ex, "Process terminating."); /// [MessageTemplateFormatMethod("messageTemplate")] - public static void Fatal(Exception exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1) + public static void Fatal(Exception? exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1) { Write(LogEventLevel.Fatal, exception, messageTemplate, propertyValue0, propertyValue1); } @@ -1129,7 +1129,7 @@ public static void Fatal(Exception exception, string messageTemplate, T prope /// Log.Fatal(ex, "Process terminating."); /// [MessageTemplateFormatMethod("messageTemplate")] - public static void Fatal(Exception exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1, T2 propertyValue2) + public static void Fatal(Exception? exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1, T2 propertyValue2) { Write(LogEventLevel.Fatal, exception, messageTemplate, propertyValue0, propertyValue1, propertyValue2); } @@ -1144,7 +1144,7 @@ public static void Fatal(Exception exception, string messageTemplate, T prope /// Log.Fatal(ex, "Process terminating."); /// [MessageTemplateFormatMethod("messageTemplate")] - public static void Fatal(Exception exception, string messageTemplate, params object?[]? propertyValues) + public static void Fatal(Exception? exception, string messageTemplate, params object?[]? propertyValues) { Logger.Fatal(exception, messageTemplate, propertyValues); }