roadie/Roadie.Api.Library/Extensions/ExceptionExt.cs
2020-08-02 13:18:48 -05:00

28 lines
No EOL
648 B
C#

using System;
using System.Text.Json;
namespace Roadie.Library.Extensions
{
public static class ExceptionExt
{
public static string Serialize(this Exception input)
{
if (input == null)
{
return null;
}
try
{
return JsonSerializer.Serialize(input, new JsonSerializerOptions
{
IgnoreNullValues = true,
WriteIndented = true
});
}
catch (Exception)
{
return input?.ToString();
}
}
}
}