-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(Logger): add a Logger class and refactor
- Loading branch information
1 parent
9c84fa4
commit 2a4d404
Showing
9 changed files
with
141 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
using System.Runtime.CompilerServices; | ||
using System; | ||
|
||
namespace PollinationSDK | ||
{ | ||
public static class LogHelper | ||
{ | ||
public static Serilog.ILogger Logger | ||
{ | ||
get => Helper.Logger; | ||
set => Helper.Logger = value; | ||
} | ||
|
||
public static void LogInfo(string message, [CallerMemberName] string memberName = "") | ||
{ | ||
Logger?.Information("{memberName}:{message}", memberName, message); | ||
} | ||
public static void LogWarning(string message, [CallerMemberName] string memberName = "") | ||
{ | ||
Logger?.Warning("{memberName}:{message}", memberName, message); | ||
} | ||
|
||
public static void LogError(string ex, [CallerMemberName] string memberName = "") | ||
{ | ||
Logger?.Error("{memberName}:{ex}", memberName, ex); | ||
} | ||
|
||
public static void LogError(Exception ex, [CallerMemberName] string memberName = "") | ||
{ | ||
Logger?.Error(ex, "{memberName}", memberName); | ||
} | ||
|
||
/// <summary> | ||
/// Log and throw the error | ||
/// </summary> | ||
/// <param name="ex"></param> | ||
/// <param name="memberName"></param> | ||
public static void LogThrowError(string ex, [CallerMemberName] string memberName = "") | ||
{ | ||
LogThrowError(new ArgumentException(ex), memberName); | ||
} | ||
|
||
/// <summary> | ||
/// Log and throw the error | ||
/// </summary> | ||
/// <param name="ex"></param> | ||
/// <param name="memberName"></param> | ||
public static void LogThrowError(Exception ex, [CallerMemberName] string memberName = "") | ||
{ | ||
Logger?.Error(ex, "{memberName}", memberName); | ||
throw ex; | ||
} | ||
|
||
public static Exception LogReturnError(string ex, [CallerMemberName] string memberName = "") | ||
{ | ||
return LogReturnError(new ArgumentException(ex), memberName); | ||
} | ||
|
||
public static Exception LogReturnError(Exception ex, [CallerMemberName] string memberName = "") | ||
{ | ||
Logger?.Error(ex, "{memberName}", memberName); | ||
return ex; | ||
} | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.