Files
speckle-sharp-connectors/DUI3/Speckle.Connectors.DUI/Logging/BindingErrorLogging.cs
T
Jedd Morgan 46bb442f02 CNXPLA-19: Add logging for model card handled exceptions (#118)
* Add logging for model card handled exceptions

* Arcgis logger

* Polish
2024-08-09 10:42:38 +00:00

27 lines
916 B
C#

using Microsoft.Extensions.Logging;
using Speckle.Connectors.DUI.Bindings;
using Speckle.Sdk;
namespace Speckle.Connectors.DUI.Logging;
/// <remarks>
/// These helper functions are designed because we are handling all <see cref="Exception"/>s using the model card
/// But we still would like to discriminate the severity via logging.
/// If we ever decide to be more specific with our exception catching within bindings (to allow unexpected exceptions to bubble up to the top level)
/// then these functions likely won't be useful.
/// </remarks>
public static class HandledModelCardErrors
{
public static void LogModelCardHandledError<T>(this ILogger<T> logger, Exception ex)
where T : IBinding
{
LogLevel level = ex switch
{
SpeckleException => LogLevel.Warning,
_ => LogLevel.Error
};
logger.Log(level, ex, "{bindingType} operation was not successful", typeof(T));
}
}