mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-17 13:45:05 +00:00
Revert "fix: fix for logging deadlock, use mutexes, add logging for last message sent."
This reverts commit 7c238b9fef.
This commit is contained in:
@@ -8,44 +8,35 @@ namespace ICD.Common.Utils
|
|||||||
{
|
{
|
||||||
public static class IcdErrorLog
|
public static class IcdErrorLog
|
||||||
{
|
{
|
||||||
private const int MUTEX_TIMEOUT = 30 * 1000;
|
private static readonly SafeCriticalSection s_LoggingSection;
|
||||||
private static readonly SafeMutex s_SafeMutex;
|
|
||||||
private static string s_LastMessage;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Static constructor.
|
/// Static constructor.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
static IcdErrorLog()
|
static IcdErrorLog()
|
||||||
{
|
{
|
||||||
s_SafeMutex = new SafeMutex();
|
s_LoggingSection = new SafeCriticalSection();
|
||||||
}
|
}
|
||||||
|
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public static void Error(string message)
|
public static void Error(string message)
|
||||||
{
|
{
|
||||||
if(s_SafeMutex.WaitForMutex(MUTEX_TIMEOUT))
|
s_LoggingSection.Enter();
|
||||||
|
|
||||||
|
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);
|
||||||
#else
|
#else
|
||||||
System.Console.ForegroundColor = ConsoleColor.Red;
|
System.Console.ForegroundColor = ConsoleColor.Red;
|
||||||
System.Console.Error.WriteLine(message);
|
System.Console.Error.WriteLine(message);
|
||||||
System.Console.ResetColor();
|
System.Console.ResetColor();
|
||||||
#endif
|
#endif
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
s_SafeMutex.ReleaseMutex();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
finally
|
||||||
{
|
{
|
||||||
IcdConsole.PrintLine(eConsoleColor.YellowOnRed, "Deadlock in Error Logging, last logged message is:");
|
s_LoggingSection.Leave();
|
||||||
IcdConsole.PrintLine(eConsoleColor.YellowOnRed, StringUtils.ToMixedReadableHexLiteral(s_LastMessage));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,29 +49,22 @@ namespace ICD.Common.Utils
|
|||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public static void Warn(string message)
|
public static void Warn(string message)
|
||||||
{
|
{
|
||||||
if (s_SafeMutex.WaitForMutex(MUTEX_TIMEOUT))
|
s_LoggingSection.Enter();
|
||||||
|
|
||||||
|
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);
|
||||||
#else
|
#else
|
||||||
System.Console.ForegroundColor = ConsoleColor.Yellow;
|
System.Console.ForegroundColor = ConsoleColor.Yellow;
|
||||||
System.Console.Error.WriteLine(message);
|
System.Console.Error.WriteLine(message);
|
||||||
System.Console.ResetColor();
|
System.Console.ResetColor();
|
||||||
#endif
|
#endif
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
s_SafeMutex.ReleaseMutex();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
finally
|
||||||
{
|
{
|
||||||
IcdConsole.PrintLine(eConsoleColor.YellowOnRed, "Deadlock in Error Logging, last logged message is:");
|
s_LoggingSection.Leave();
|
||||||
IcdConsole.PrintLine(eConsoleColor.YellowOnRed, StringUtils.ToMixedReadableHexLiteral(s_LastMessage));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,29 +77,22 @@ namespace ICD.Common.Utils
|
|||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public static void Notice(string message)
|
public static void Notice(string message)
|
||||||
{
|
{
|
||||||
if (s_SafeMutex.WaitForMutex(MUTEX_TIMEOUT))
|
s_LoggingSection.Enter();
|
||||||
|
|
||||||
|
try
|
||||||
{
|
{
|
||||||
s_LastMessage = message;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
#if SIMPLSHARP
|
#if SIMPLSHARP
|
||||||
message = FormatConsoleColor(message, ConsoleColorExtensions.CONSOLE_BLUE);
|
message = FormatConsoleColor(message, ConsoleColorExtensions.CONSOLE_BLUE);
|
||||||
ErrorLog.Notice(message);
|
ErrorLog.Notice(message);
|
||||||
#else
|
#else
|
||||||
System.Console.ForegroundColor = ConsoleColor.Blue;
|
System.Console.ForegroundColor = ConsoleColor.Blue;
|
||||||
System.Console.Error.WriteLine(message);
|
System.Console.Error.WriteLine(message);
|
||||||
System.Console.ResetColor();
|
System.Console.ResetColor();
|
||||||
#endif
|
#endif
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
s_SafeMutex.ReleaseMutex();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
finally
|
||||||
{
|
{
|
||||||
IcdConsole.PrintLine(eConsoleColor.YellowOnRed, "Deadlock in Error Logging, last logged message is:");
|
s_LoggingSection.Leave();
|
||||||
IcdConsole.PrintLine(eConsoleColor.YellowOnRed, StringUtils.ToMixedReadableHexLiteral(s_LastMessage));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,29 +105,22 @@ namespace ICD.Common.Utils
|
|||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public static void Ok(string message)
|
public static void Ok(string message)
|
||||||
{
|
{
|
||||||
if (s_SafeMutex.WaitForMutex(MUTEX_TIMEOUT))
|
s_LoggingSection.Enter();
|
||||||
|
|
||||||
|
try
|
||||||
{
|
{
|
||||||
s_LastMessage = message;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
#if SIMPLSHARP
|
#if SIMPLSHARP
|
||||||
message = FormatConsoleColor(message, ConsoleColorExtensions.CONSOLE_GREEN);
|
message = FormatConsoleColor(message, ConsoleColorExtensions.CONSOLE_GREEN);
|
||||||
ErrorLog.Ok(message);
|
ErrorLog.Ok(message);
|
||||||
#else
|
#else
|
||||||
System.Console.ForegroundColor = ConsoleColor.Green;
|
System.Console.ForegroundColor = ConsoleColor.Green;
|
||||||
System.Console.Error.WriteLine(message);
|
System.Console.Error.WriteLine(message);
|
||||||
System.Console.ResetColor();
|
System.Console.ResetColor();
|
||||||
#endif
|
#endif
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
s_SafeMutex.ReleaseMutex();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
finally
|
||||||
{
|
{
|
||||||
IcdConsole.PrintLine(eConsoleColor.YellowOnRed, "Deadlock in Error Logging, last logged message is:");
|
s_LoggingSection.Leave();
|
||||||
IcdConsole.PrintLine(eConsoleColor.YellowOnRed, StringUtils.ToMixedReadableHexLiteral(s_LastMessage));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -163,14 +133,13 @@ namespace ICD.Common.Utils
|
|||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public static void Exception(Exception ex, string message)
|
public static void Exception(Exception ex, string message)
|
||||||
{
|
{
|
||||||
if (s_SafeMutex.WaitForMutex(MUTEX_TIMEOUT))
|
s_LoggingSection.Enter();
|
||||||
|
|
||||||
|
try
|
||||||
{
|
{
|
||||||
s_LastMessage = message;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
#if SIMPLSHARP
|
#if SIMPLSHARP
|
||||||
message = FormatConsoleColor(message, ConsoleColorExtensions.CONSOLE_YELLOW_ON_RED_BACKGROUND);
|
message = FormatConsoleColor(message, ConsoleColorExtensions.CONSOLE_YELLOW_ON_RED_BACKGROUND);
|
||||||
ErrorLog.Exception(message, ex);
|
ErrorLog.Exception(message, ex);
|
||||||
#else
|
#else
|
||||||
System.Console.ForegroundColor = ConsoleColor.Yellow;
|
System.Console.ForegroundColor = ConsoleColor.Yellow;
|
||||||
System.Console.BackgroundColor = ConsoleColor.Red;
|
System.Console.BackgroundColor = ConsoleColor.Red;
|
||||||
@@ -178,16 +147,10 @@ namespace ICD.Common.Utils
|
|||||||
System.Console.ResetColor();
|
System.Console.ResetColor();
|
||||||
System.Console.Error.WriteLine(ex.StackTrace);
|
System.Console.Error.WriteLine(ex.StackTrace);
|
||||||
#endif
|
#endif
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
s_SafeMutex.ReleaseMutex();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
finally
|
||||||
{
|
{
|
||||||
IcdConsole.PrintLine(eConsoleColor.YellowOnRed, "Deadlock in Error Logging, last logged message is:");
|
s_LoggingSection.Leave();
|
||||||
IcdConsole.PrintLine(eConsoleColor.YellowOnRed, StringUtils.ToMixedReadableHexLiteral(s_LastMessage));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -201,29 +164,22 @@ namespace ICD.Common.Utils
|
|||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public static void Info(string message)
|
public static void Info(string message)
|
||||||
{
|
{
|
||||||
if (s_SafeMutex.WaitForMutex(MUTEX_TIMEOUT))
|
s_LoggingSection.Enter();
|
||||||
|
|
||||||
|
try
|
||||||
{
|
{
|
||||||
s_LastMessage = message;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
#if SIMPLSHARP
|
#if SIMPLSHARP
|
||||||
message = FormatConsoleColor(message, ConsoleColorExtensions.CONSOLE_CYAN);
|
message = FormatConsoleColor(message, ConsoleColorExtensions.CONSOLE_CYAN);
|
||||||
ErrorLog.Info(message);
|
ErrorLog.Info(message);
|
||||||
#else
|
#else
|
||||||
System.Console.ForegroundColor = ConsoleColor.Cyan;
|
System.Console.ForegroundColor = ConsoleColor.Cyan;
|
||||||
System.Console.Error.WriteLine(message);
|
System.Console.Error.WriteLine(message);
|
||||||
System.Console.ResetColor();
|
System.Console.ResetColor();
|
||||||
#endif
|
#endif
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
s_SafeMutex.ReleaseMutex();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
finally
|
||||||
{
|
{
|
||||||
IcdConsole.PrintLine(eConsoleColor.YellowOnRed, "Deadlock in Error Logging, last logged message is:");
|
s_LoggingSection.Leave();
|
||||||
IcdConsole.PrintLine(eConsoleColor.YellowOnRed, StringUtils.ToMixedReadableHexLiteral(s_LastMessage));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user