Skip to content
This repository was archived by the owner on Nov 2, 2018. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Source/EasyGelf.Core/SilentLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,34 @@ 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)
{
}

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;
}
}
}
}
2 changes: 2 additions & 0 deletions Source/EasyGelf.Core/Transports/BufferedTransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public BufferedTransport(IEasyGelfLogger logger, ITransport transport)
catch(Exception exception)
{
logger.Error("Cannot send message", exception);
logger.SetException(exception);
}
}
}
Expand All @@ -42,6 +43,7 @@ public BufferedTransport(IEasyGelfLogger logger, ITransport transport)
catch (Exception exception)
{
logger.Error("Cannot send message", exception);
logger.SetException(exception);
}
}
}
Expand Down
15 changes: 15 additions & 0 deletions Source/EasyGelf.Log4Net/VerboseLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}
}
}
}
2 changes: 2 additions & 0 deletions Source/EasyGelf.NLog/GelfTargetBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
14 changes: 14 additions & 0 deletions Source/EasyGelf.NLog/VerboseLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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;
}
}
}
}