mirror of
https://github.com/sphildreth/roadie
synced 2024-11-10 06:44:12 +00:00
28 lines
No EOL
716 B
C#
28 lines
No EOL
716 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
|
|
{
|
|
DefaultIgnoreCondition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull,
|
|
WriteIndented = true
|
|
});
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return input?.ToString();
|
|
}
|
|
}
|
|
}
|
|
} |