sonarr-repo-only/NzbDrone.Common/Instrumentation/LogEventExtensions.cs

40 lines
1.1 KiB
C#
Raw Normal View History

2013-05-24 03:23:59 +00:00
using System;
using NLog;
using NzbDrone.Common.Serializer;
namespace NzbDrone.Common.Instrumentation
{
public static class LogEventExtensions
{
public static string GetHash(this LogEventInfo logEvent)
{
var stackString = logEvent.StackTrace.ToJson();
2013-05-24 03:23:59 +00:00
var hashSeed = String.Concat(logEvent.LoggerName, logEvent.Exception.GetType().ToString(), stackString, logEvent.Level);
return HashUtil.CalculateCrc(hashSeed);
}
public static string GetFormattedMessage(this LogEventInfo logEvent)
{
var message = logEvent.FormattedMessage;
if (logEvent.Exception != null)
{
if (logEvent.Exception != null)
{
if (String.IsNullOrWhiteSpace(message))
{
message = logEvent.Exception.Message;
}
else
{
message += ": " + logEvent.Exception.Message;
}
}
}
return message;
}
}
}