You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
980 B
32 lines
980 B
using System;
|
|
using System.Globalization;
|
|
using System.Runtime.CompilerServices;
|
|
|
|
namespace Infrastructure.Extensions
|
|
{
|
|
public static class ExceptionExtensions
|
|
{
|
|
public static void PrintStack(this Exception ex, string rawMessage = null, [CallerMemberName] string memberName = "")
|
|
{
|
|
if (ex is null)
|
|
{
|
|
throw new ArgumentNullException(nameof(ex));
|
|
}
|
|
|
|
Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff", CultureInfo.CurrentCulture));
|
|
if (rawMessage != null)
|
|
{
|
|
Console.WriteLine(rawMessage);
|
|
}
|
|
Console.WriteLine(memberName);
|
|
Console.WriteLine(ex.Message);
|
|
Console.WriteLine(ex.StackTrace);
|
|
ex.InnerException?.PrintStack();
|
|
}
|
|
|
|
public static string GetMessage(this Exception ex)
|
|
{
|
|
return ex?.InnerException?.Message ?? ex.Message;
|
|
}
|
|
}
|
|
} |