using Serilog;
using System;
using TINK.Repository.Exception;
namespace TINK.Model.Logging
{
public static class LogEntryClassifyHelper
{
/// Classifies exception and logs information or error depending on result of classification.
/// Type of first message parameter.
/// Type of second message parameter.
/// Object to use for logging.
/// Templated used to output message.
/// First message parameter.
/// Second message parameter.
/// Exception to classify.
public static void InformationOrError(this ILogger p_oLogger, string messageTemplate, T0 propertyValue0, T1 propertyValue1, Exception p_oException)
{
if (p_oException == null)
{
p_oLogger.Error(messageTemplate, propertyValue0, propertyValue1, string.Empty);
return;
}
if (p_oException.GetIsConnectFailureException())
{
// Expected exception (LAN or mobile data off/ not reachable, proxy, ...)
p_oLogger.Information(messageTemplate, propertyValue0, propertyValue1, p_oException);
return;
}
p_oLogger.Error(messageTemplate, propertyValue0, propertyValue1, p_oException);
}
}
}