mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-04-12 12:07:05 +00:00
fix: fix for logging deadlock, use mutexes, add logging for last message sent.
This commit is contained in:
parent
1be852685d
commit
7c238b9fef
1 changed files with 88 additions and 44 deletions
|
|
@ -8,23 +8,26 @@ namespace ICD.Common.Utils
|
|||
{
|
||||
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>
|
||||
/// Static constructor.
|
||||
/// </summary>
|
||||
static IcdErrorLog()
|
||||
{
|
||||
s_LoggingSection = new SafeCriticalSection();
|
||||
s_SafeMutex = new SafeMutex();
|
||||
}
|
||||
|
||||
[PublicAPI]
|
||||
public static void Error(string message)
|
||||
{
|
||||
s_LoggingSection.Enter();
|
||||
|
||||
if(s_SafeMutex.WaitForMutex(MUTEX_TIMEOUT))
|
||||
{
|
||||
try
|
||||
{
|
||||
s_LastMessage = message;
|
||||
#if SIMPLSHARP
|
||||
message = FormatConsoleColor(message, ConsoleColorExtensions.CONSOLE_RED);
|
||||
ErrorLog.Error(message);
|
||||
|
|
@ -36,7 +39,13 @@ namespace ICD.Common.Utils
|
|||
}
|
||||
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]
|
||||
public static void Warn(string message)
|
||||
{
|
||||
s_LoggingSection.Enter();
|
||||
|
||||
if (s_SafeMutex.WaitForMutex(MUTEX_TIMEOUT))
|
||||
{
|
||||
try
|
||||
{
|
||||
s_LastMessage = message;
|
||||
#if SIMPLSHARP
|
||||
message = FormatConsoleColor(message, ConsoleColorExtensions.CONSOLE_YELLOW);
|
||||
ErrorLog.Warn(message);
|
||||
|
|
@ -64,7 +74,13 @@ namespace ICD.Common.Utils
|
|||
}
|
||||
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]
|
||||
public static void Notice(string message)
|
||||
{
|
||||
s_LoggingSection.Enter();
|
||||
|
||||
if (s_SafeMutex.WaitForMutex(MUTEX_TIMEOUT))
|
||||
{
|
||||
s_LastMessage = message;
|
||||
try
|
||||
{
|
||||
#if SIMPLSHARP
|
||||
|
|
@ -92,7 +109,13 @@ namespace ICD.Common.Utils
|
|||
}
|
||||
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]
|
||||
public static void Ok(string message)
|
||||
{
|
||||
s_LoggingSection.Enter();
|
||||
|
||||
if (s_SafeMutex.WaitForMutex(MUTEX_TIMEOUT))
|
||||
{
|
||||
s_LastMessage = message;
|
||||
try
|
||||
{
|
||||
#if SIMPLSHARP
|
||||
|
|
@ -120,7 +144,13 @@ namespace ICD.Common.Utils
|
|||
}
|
||||
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]
|
||||
public static void Exception(Exception ex, string message)
|
||||
{
|
||||
s_LoggingSection.Enter();
|
||||
|
||||
if (s_SafeMutex.WaitForMutex(MUTEX_TIMEOUT))
|
||||
{
|
||||
s_LastMessage = message;
|
||||
try
|
||||
{
|
||||
#if SIMPLSHARP
|
||||
|
|
@ -150,7 +181,13 @@ namespace ICD.Common.Utils
|
|||
}
|
||||
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]
|
||||
public static void Info(string message)
|
||||
{
|
||||
s_LoggingSection.Enter();
|
||||
|
||||
if (s_SafeMutex.WaitForMutex(MUTEX_TIMEOUT))
|
||||
{
|
||||
s_LastMessage = message;
|
||||
try
|
||||
{
|
||||
#if SIMPLSHARP
|
||||
|
|
@ -179,7 +217,13 @@ namespace ICD.Common.Utils
|
|||
}
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue