077ac246a8
Co-authored-by: Dimitrie Stefanescu <didimitrie@gmail.com> Co-authored-by: Oğuzhan Koral <45078678+oguzhankoral@users.noreply.github.com>
37 lines
970 B
C#
37 lines
970 B
C#
using Microsoft.Extensions.Logging;
|
|
using Speckle.Converters.Common.Objects;
|
|
using Speckle.Sdk;
|
|
using Speckle.Sdk.Models;
|
|
|
|
namespace Speckle.Converters.Common.Extensions;
|
|
|
|
public static class ToHostTopLevelConverterExtension
|
|
{
|
|
public static object ConvertAndLog(this IToHostTopLevelConverter converter, Base target, ILogger logger)
|
|
{
|
|
try
|
|
{
|
|
return converter.Convert(target);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//SpeckleExceptions are expected, if a converter throws anything else, its considered an error that we should investigate and fix
|
|
LogLevel logLevel = ex switch
|
|
{
|
|
SpeckleException => LogLevel.Information, //If it's too noisy, we could demote to LogLevel.Debug
|
|
_ => LogLevel.Error
|
|
};
|
|
|
|
logger.Log(
|
|
logLevel,
|
|
ex,
|
|
"Conversion of object {target} using {converter} was not successful",
|
|
target.GetType(),
|
|
converter.GetType()
|
|
);
|
|
|
|
throw;
|
|
}
|
|
}
|
|
}
|