Skip to content
This repository has been archived by the owner on Dec 21, 2024. It is now read-only.

Commit

Permalink
Fix: Return Exception instead of throw
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasSasDev committed Sep 4, 2024
1 parent 84466a2 commit 7a7c2a9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package >
<metadata>
<id>CodeOfChaos.Extensions.Serilog</id>
<version>0.3.1</version>
<version>0.4.0</version>
<authors>AndreasSasDev</authors>
<owners></owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
Expand Down
25 changes: 10 additions & 15 deletions src/CodeOfChaos.Extensions.Serilog/LoggerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@ public static class LoggerExtensions {
/// <param name="propertyValues">The property values.</param>
/// <exception cref="Exception">Thrown exception.</exception>
[MessageTemplateFormatMethod("messageTemplate")]
[DoesNotReturn] [AssertionMethod]
[UsedImplicitly]
public static void ThrowError(this ILogger logger, string messageTemplate, params object?[]? propertyValues) {
public static Exception ThrowError(this ILogger logger, string messageTemplate, params object?[]? propertyValues) {
var exception = (Exception)Activator.CreateInstance(typeof(Exception), messageTemplate)!;
logger.Error(exception, messageTemplate, propertyValues);
throw exception;
return exception;
}

/// <summary>
Expand All @@ -39,12 +38,11 @@ public static void ThrowError(this ILogger logger, string messageTemplate, param
/// <param name="messageTemplate">The message template for the exception.</param>
/// <param name="propertyValues">The property values for the exception.</param>
[MessageTemplateFormatMethod("messageTemplate")]
[DoesNotReturn] [AssertionMethod]
[UsedImplicitly]
public static void ThrowError<TException>(this ILogger logger, string messageTemplate, params object?[]? propertyValues) where TException : Exception, new() {
public static TException ThrowError<TException>(this ILogger logger, string messageTemplate, params object?[]? propertyValues) where TException : Exception, new() {
var exception = (TException)Activator.CreateInstance(typeof(TException), messageTemplate)!;
logger.Error(exception, messageTemplate, propertyValues);
throw exception;
return exception;
}

/// <summary>
Expand All @@ -55,12 +53,11 @@ [DoesNotReturn] [AssertionMethod]
/// <param name="propertyValues">The property values.</param>
/// <exception cref="Exception">Thrown exception.</exception>
[MessageTemplateFormatMethod("messageTemplate")]
[DoesNotReturn] [AssertionMethod]
[UsedImplicitly]
public static void ThrowFatal(this ILogger logger, string messageTemplate, params object?[]? propertyValues) {
public static Exception ThrowFatal(this ILogger logger, string messageTemplate, params object?[]? propertyValues) {
var exception = (Exception)Activator.CreateInstance(typeof(Exception), messageTemplate)!;
logger.Fatal(exception, messageTemplate, propertyValues);
throw exception;
return exception;
}

/// <summary>
Expand All @@ -71,12 +68,11 @@ public static void ThrowFatal(this ILogger logger, string messageTemplate, param
/// <param name="messageTemplate">The message template for the exception.</param>
/// <param name="propertyValues">The property values for the exception.</param>
[MessageTemplateFormatMethod("messageTemplate")]
[DoesNotReturn] [AssertionMethod]
[UsedImplicitly]
public static void ThrowFatal<TException>(this ILogger logger, string messageTemplate, params object?[]? propertyValues) where TException : Exception, new() {
public static TException ThrowFatal<TException>(this ILogger logger, string messageTemplate, params object?[]? propertyValues) where TException : Exception, new() {
var exception = (TException)Activator.CreateInstance(typeof(TException), messageTemplate)!;
logger.Fatal(exception, messageTemplate, propertyValues);
throw exception;
return exception;
}

/// <summary>
Expand All @@ -87,11 +83,10 @@ [DoesNotReturn] [AssertionMethod]
/// <param name="exception">The type of expection to be thrown.</param>
/// <param name="propertyValues">The property values to be used for formatting the message.</param>
[MessageTemplateFormatMethod("messageTemplate")]
[DoesNotReturn] [AssertionMethod]
[UsedImplicitly]
public static void ThrowFatal<TException>(this ILogger logger, TException exception, string messageTemplate, params object?[]? propertyValues) where TException : Exception {
public static TException ThrowFatal<TException>(this ILogger logger, TException exception, string messageTemplate, params object?[]? propertyValues) where TException : Exception {
logger.Fatal(exception, messageTemplate, propertyValues);
throw exception;
return exception;
}

/// <summary>
Expand Down

0 comments on commit 7a7c2a9

Please sign in to comment.