mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-16 13:15:07 +00:00
fix: fix for logging deadlock, use mutexes, add logging for last message sent.
This commit is contained in:
@@ -8,23 +8,26 @@ namespace ICD.Common.Utils
|
|||||||
{
|
{
|
||||||
public static class IcdErrorLog
|
public static class IcdErrorLog
|
||||||
{
|
{
|
||||||
private static readonly SafeCriticalSection s_LoggingSection;
|
private const int MUTEX_TIMEOUT = 30 * 1000;
|
||||||
|
private static readonly SafeMutex s_SafeMutex;
|
||||||
|
private static string s_LastMessage;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Static constructor.
|
/// Static constructor.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
static IcdErrorLog()
|
static IcdErrorLog()
|
||||||
{
|
{
|
||||||
s_LoggingSection = new SafeCriticalSection();
|
s_SafeMutex = new SafeMutex();
|
||||||
}
|
}
|
||||||
|
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public static void Error(string message)
|
public static void Error(string message)
|
||||||
{
|
{
|
||||||
s_LoggingSection.Enter();
|
if(s_SafeMutex.WaitForMutex(MUTEX_TIMEOUT))
|
||||||
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
s_LastMessage = message;
|
||||||
#if SIMPLSHARP
|
#if SIMPLSHARP
|
||||||
message = FormatConsoleColor(message, ConsoleColorExtensions.CONSOLE_RED);
|
message = FormatConsoleColor(message, ConsoleColorExtensions.CONSOLE_RED);
|
||||||
ErrorLog.Error(message);
|
ErrorLog.Error(message);
|
||||||
@@ -36,7 +39,13 @@ namespace ICD.Common.Utils
|
|||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
s_LoggingSection.Leave();
|
s_SafeMutex.ReleaseMutex();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
IcdConsole.PrintLine(eConsoleColor.YellowOnRed, "Deadlock in Error Logging, last logged message is:");
|
||||||
|
IcdConsole.PrintLine(eConsoleColor.YellowOnRed, StringUtils.ToMixedReadableHexLiteral(s_LastMessage));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,10 +58,11 @@ namespace ICD.Common.Utils
|
|||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public static void Warn(string message)
|
public static void Warn(string message)
|
||||||
{
|
{
|
||||||
s_LoggingSection.Enter();
|
if (s_SafeMutex.WaitForMutex(MUTEX_TIMEOUT))
|
||||||
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
s_LastMessage = message;
|
||||||
#if SIMPLSHARP
|
#if SIMPLSHARP
|
||||||
message = FormatConsoleColor(message, ConsoleColorExtensions.CONSOLE_YELLOW);
|
message = FormatConsoleColor(message, ConsoleColorExtensions.CONSOLE_YELLOW);
|
||||||
ErrorLog.Warn(message);
|
ErrorLog.Warn(message);
|
||||||
@@ -64,7 +74,13 @@ namespace ICD.Common.Utils
|
|||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
s_LoggingSection.Leave();
|
s_SafeMutex.ReleaseMutex();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
IcdConsole.PrintLine(eConsoleColor.YellowOnRed, "Deadlock in Error Logging, last logged message is:");
|
||||||
|
IcdConsole.PrintLine(eConsoleColor.YellowOnRed, StringUtils.ToMixedReadableHexLiteral(s_LastMessage));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,8 +93,9 @@ namespace ICD.Common.Utils
|
|||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public static void Notice(string message)
|
public static void Notice(string message)
|
||||||
{
|
{
|
||||||
s_LoggingSection.Enter();
|
if (s_SafeMutex.WaitForMutex(MUTEX_TIMEOUT))
|
||||||
|
{
|
||||||
|
s_LastMessage = message;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
#if SIMPLSHARP
|
#if SIMPLSHARP
|
||||||
@@ -92,7 +109,13 @@ namespace ICD.Common.Utils
|
|||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
s_LoggingSection.Leave();
|
s_SafeMutex.ReleaseMutex();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
IcdConsole.PrintLine(eConsoleColor.YellowOnRed, "Deadlock in Error Logging, last logged message is:");
|
||||||
|
IcdConsole.PrintLine(eConsoleColor.YellowOnRed, StringUtils.ToMixedReadableHexLiteral(s_LastMessage));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,8 +128,9 @@ namespace ICD.Common.Utils
|
|||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public static void Ok(string message)
|
public static void Ok(string message)
|
||||||
{
|
{
|
||||||
s_LoggingSection.Enter();
|
if (s_SafeMutex.WaitForMutex(MUTEX_TIMEOUT))
|
||||||
|
{
|
||||||
|
s_LastMessage = message;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
#if SIMPLSHARP
|
#if SIMPLSHARP
|
||||||
@@ -120,7 +144,13 @@ namespace ICD.Common.Utils
|
|||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
s_LoggingSection.Leave();
|
s_SafeMutex.ReleaseMutex();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
IcdConsole.PrintLine(eConsoleColor.YellowOnRed, "Deadlock in Error Logging, last logged message is:");
|
||||||
|
IcdConsole.PrintLine(eConsoleColor.YellowOnRed, StringUtils.ToMixedReadableHexLiteral(s_LastMessage));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,8 +163,9 @@ namespace ICD.Common.Utils
|
|||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public static void Exception(Exception ex, string message)
|
public static void Exception(Exception ex, string message)
|
||||||
{
|
{
|
||||||
s_LoggingSection.Enter();
|
if (s_SafeMutex.WaitForMutex(MUTEX_TIMEOUT))
|
||||||
|
{
|
||||||
|
s_LastMessage = message;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
#if SIMPLSHARP
|
#if SIMPLSHARP
|
||||||
@@ -150,7 +181,13 @@ namespace ICD.Common.Utils
|
|||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
s_LoggingSection.Leave();
|
s_SafeMutex.ReleaseMutex();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
IcdConsole.PrintLine(eConsoleColor.YellowOnRed, "Deadlock in Error Logging, last logged message is:");
|
||||||
|
IcdConsole.PrintLine(eConsoleColor.YellowOnRed, StringUtils.ToMixedReadableHexLiteral(s_LastMessage));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -164,8 +201,9 @@ namespace ICD.Common.Utils
|
|||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public static void Info(string message)
|
public static void Info(string message)
|
||||||
{
|
{
|
||||||
s_LoggingSection.Enter();
|
if (s_SafeMutex.WaitForMutex(MUTEX_TIMEOUT))
|
||||||
|
{
|
||||||
|
s_LastMessage = message;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
#if SIMPLSHARP
|
#if SIMPLSHARP
|
||||||
@@ -179,7 +217,13 @@ namespace ICD.Common.Utils
|
|||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
s_LoggingSection.Leave();
|
s_SafeMutex.ReleaseMutex();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
IcdConsole.PrintLine(eConsoleColor.YellowOnRed, "Deadlock in Error Logging, last logged message is:");
|
||||||
|
IcdConsole.PrintLine(eConsoleColor.YellowOnRed, StringUtils.ToMixedReadableHexLiteral(s_LastMessage));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user