-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLogUtils.cs
More file actions
23 lines (22 loc) · 916 Bytes
/
LogUtils.cs
File metadata and controls
23 lines (22 loc) · 916 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
using Microsoft.Extensions.Logging;
namespace Utils
{
public static class LogUtils
{
/// <summary>
/// Log <see cref="TException"/> and return it
/// </summary>
/// <param name="logger">Logger instance</param>
/// <param name="exception">Exception to log</param>
/// <param name="logLevel">Specify <see cref="LogLevel"/>. Default is <see cref="LogLevel.Critical"/></param>
/// <typeparam name="TException"></typeparam>
/// <returns>Return exception to further manipulations</returns>
public static TException LogExceptionMessage<TException>(this TException exception, ILogger logger,
LogLevel logLevel = LogLevel.Critical)
where TException : Exception
{
logger.Log(logLevel, exception, "Exception was thrown: {Message}", exception.Message);
return exception;
}
}
}