2022-08-30 15:42:25 +02:00
|
|
|
|
using System;
|
|
|
|
|
using Serilog;
|
2021-06-26 20:57:55 +02:00
|
|
|
|
using TINK.Repository.Exception;
|
2021-05-13 20:03:07 +02:00
|
|
|
|
|
|
|
|
|
namespace TINK.Model.Logging
|
|
|
|
|
{
|
2022-09-06 16:08:19 +02:00
|
|
|
|
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;
|
|
|
|
|
}
|
2021-05-13 20:03:07 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
if (p_oException.GetIsConnectFailureException())
|
|
|
|
|
{
|
|
|
|
|
// Expected exception (LAN or mobile data off/ not reachable, proxy, ...)
|
|
|
|
|
p_oLogger.Information(messageTemplate, propertyValue0, propertyValue1, p_oException);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-05-13 20:03:07 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
p_oLogger.Error(messageTemplate, propertyValue0, propertyValue1, p_oException);
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-05-13 20:03:07 +02:00
|
|
|
|
}
|