diff --git a/Source/EasyGelf.Core/SilentLogger.cs b/Source/EasyGelf.Core/SilentLogger.cs index 36b86ae..46f4b80 100644 --- a/Source/EasyGelf.Core/SilentLogger.cs +++ b/Source/EasyGelf.Core/SilentLogger.cs @@ -6,10 +6,14 @@ public interface IEasyGelfLogger { void Error(string message, Exception exception); void Debug(string message); + void SetException(Exception e); + void CheckException(); } public sealed class SilentLogger : IEasyGelfLogger { + private static Exception threadException = null; + public void Error(string message, Exception exception) { } @@ -17,5 +21,19 @@ public void Error(string message, Exception exception) public void Debug(string message) { } + + public void SetException(Exception exception) + { + threadException = exception; + } + public void CheckException() + { + Exception e = threadException; + if (threadException != null) + { + threadException = null; + throw e; + } + } } } \ No newline at end of file diff --git a/Source/EasyGelf.Core/Transports/BufferedTransport.cs b/Source/EasyGelf.Core/Transports/BufferedTransport.cs index 42b8ae1..a3f6d01 100644 --- a/Source/EasyGelf.Core/Transports/BufferedTransport.cs +++ b/Source/EasyGelf.Core/Transports/BufferedTransport.cs @@ -27,6 +27,7 @@ public BufferedTransport(IEasyGelfLogger logger, ITransport transport) catch(Exception exception) { logger.Error("Cannot send message", exception); + logger.SetException(exception); } } } @@ -42,6 +43,7 @@ public BufferedTransport(IEasyGelfLogger logger, ITransport transport) catch (Exception exception) { logger.Error("Cannot send message", exception); + logger.SetException(exception); } } } diff --git a/Source/EasyGelf.Log4Net/VerboseLogger.cs b/Source/EasyGelf.Log4Net/VerboseLogger.cs index 2920ec2..2b25786 100644 --- a/Source/EasyGelf.Log4Net/VerboseLogger.cs +++ b/Source/EasyGelf.Log4Net/VerboseLogger.cs @@ -6,6 +6,7 @@ namespace EasyGelf.Log4Net { public sealed class VerboseLogger : IEasyGelfLogger { + private static Exception threadException = null; public void Error(string message, Exception exception) { LogLog.Error(typeof(VerboseLogger), message, exception); @@ -15,5 +16,19 @@ public void Debug(string message) { LogLog.Debug(typeof(VerboseLogger), message); } + public void SetException(Exception exception) + { + threadException = exception; + } + + public void CheckException() + { + Exception e = threadException; + if (threadException != null) + { + threadException = null; + throw e; + } + } } } \ No newline at end of file diff --git a/Source/EasyGelf.NLog/GelfTargetBase.cs b/Source/EasyGelf.NLog/GelfTargetBase.cs index d7ee981..93ebebd 100644 --- a/Source/EasyGelf.NLog/GelfTargetBase.cs +++ b/Source/EasyGelf.NLog/GelfTargetBase.cs @@ -106,7 +106,9 @@ protected override void Write(LogEventInfo loggingEvent) catch (Exception exception) { logger.Error("Failed to send message", exception); + throw; } + logger.CheckException(); } protected override void InitializeTarget() diff --git a/Source/EasyGelf.NLog/VerboseLogger.cs b/Source/EasyGelf.NLog/VerboseLogger.cs index 4495224..f3d9301 100644 --- a/Source/EasyGelf.NLog/VerboseLogger.cs +++ b/Source/EasyGelf.NLog/VerboseLogger.cs @@ -6,6 +6,7 @@ namespace EasyGelf.NLog { public sealed class VerboseLogger : IEasyGelfLogger { + private static Exception threadException = null; public void Error(string message, Exception exception) { InternalLogger.Error(string.Format("{0} ---> {1}", message, exception)); @@ -15,5 +16,18 @@ public void Debug(string message) { InternalLogger.Debug(message); } + public void SetException(Exception exception) + { + threadException = exception; + } + public void CheckException() + { + Exception e = threadException; + if (threadException != null) + { + threadException = null; + throw e; + } + } } } \ No newline at end of file