sharee.bike-App/TINKLib/Model/Logging/LogEntryClassifyHelper.cs
2021-06-26 20:57:55 +02:00

35 lines
1.5 KiB
C#

using Serilog;
using System;
using TINK.Repository.Exception;
namespace TINK.Model.Logging
{
public static class LogEntryClassifyHelper
{
/// <summary> Classifies exception and logs information or error depending on result of classification. </summary>
/// <typeparam name="T0">Type of first message parameter.</typeparam>
/// <typeparam name="T1">Type of second message parameter.</typeparam>
/// <param name="p_oLogger">Object to use for logging.</param>
/// <param name="messageTemplate">Templated used to output message.</param>
/// <param name="propertyValue0">First message parameter.</param>
/// <param name="propertyValue1">Second message parameter.</param>
/// <param name="p_oException">Exception to classify.</param>
public static void InformationOrError<T0, T1>(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);
}
}
}