Skip to content

Commit

Permalink
Double logging of exception messages fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
marcwittke committed Dec 15, 2018
1 parent 74397f8 commit 1d18790
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 25 deletions.
25 changes: 6 additions & 19 deletions src/implementations/Backend.Fx.Log4NetLogging/Log4NetLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ internal Log4NetLogger(ILog log4NetLogger)

public Exception Fatal(Exception exception)
{
_log4NetLogger.Fatal(GetExceptionMessages(exception), exception);
_log4NetLogger.Fatal(exception);
return exception;
}

Expand All @@ -33,7 +33,7 @@ public Exception Fatal(Exception exception, string format, params object[] args)

public Exception Error(Exception exception)
{
_log4NetLogger.Error(GetExceptionMessages(exception), exception);
_log4NetLogger.Error(exception);
return exception;
}

Expand All @@ -50,7 +50,7 @@ public Exception Error(Exception exception, string format, params object[] args)

public Exception Warn(Exception exception)
{
_log4NetLogger.Warn(GetExceptionMessages(exception), exception);
_log4NetLogger.Warn(exception);
return exception;
}

Expand All @@ -67,7 +67,7 @@ public Exception Warn(Exception exception, string format, params object[] args)

public Exception Info(Exception exception)
{
_log4NetLogger.Info(GetExceptionMessages(exception), exception);
_log4NetLogger.Info(exception);
return exception;
}

Expand Down Expand Up @@ -105,7 +105,7 @@ public bool IsDebugEnabled()

public Exception Debug(Exception exception)
{
_log4NetLogger.Debug(GetExceptionMessages(exception), exception);
_log4NetLogger.Debug(exception);
return exception;
}

Expand Down Expand Up @@ -143,7 +143,7 @@ public bool IsTraceEnabled()

public Exception Trace(Exception exception)
{
_log4NetLogger.Logger.Log(null, Level.Trace, exception.Message, exception);
_log4NetLogger.Logger.Log(null, Level.Trace, null, exception);
return exception;
}

Expand Down Expand Up @@ -174,18 +174,5 @@ public Exception Trace(Exception exception, string format, params object[] args)
}

private Level Level => ((log4net.Repository.Hierarchy.Logger)_log4NetLogger.Logger).EffectiveLevel;

private string GetExceptionMessages(Exception ex)
{
string message = ex.Message;
while (ex.InnerException != null)
{
ex = ex.InnerException;
message += System.Environment.NewLine;
message += "\t" + ex.Message;
}

return message;
}
}
}
12 changes: 6 additions & 6 deletions src/implementations/Backend.Fx.NLogLogging/NLogLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ internal NLogLogger(NLogILogger nlogLogger)
#region fatal
public Exception Fatal(Exception exception)
{
_nlogLogger.Fatal(exception, CultureInfo.InvariantCulture, exception.Message);
_nlogLogger.Fatal(exception);
return exception;
}

Expand All @@ -40,7 +40,7 @@ public Exception Fatal(Exception exception, string format, params object[] args)
#region error
public Exception Error(Exception exception)
{
_nlogLogger.Error(exception, CultureInfo.InvariantCulture, exception.Message);
_nlogLogger.Error(exception);
return exception;
}

Expand All @@ -59,7 +59,7 @@ public Exception Error(Exception exception, string format, params object[] args)
#region warn
public Exception Warn(Exception exception)
{
_nlogLogger.Warn(exception, CultureInfo.InvariantCulture, exception.Message);
_nlogLogger.Warn(exception);
return exception;
}

Expand All @@ -78,7 +78,7 @@ public Exception Warn(Exception exception, string format, params object[] args)
#region info
public Exception Info(Exception exception)
{
_nlogLogger.Info(exception, CultureInfo.InvariantCulture, exception.Message);
_nlogLogger.Info(exception);
return exception;
}

Expand Down Expand Up @@ -112,7 +112,7 @@ public bool IsDebugEnabled()

public Exception Debug(Exception exception)
{
_nlogLogger.Warn(exception, CultureInfo.InvariantCulture, exception.Message);
_nlogLogger.Warn(exception);
return exception;
}

Expand Down Expand Up @@ -147,7 +147,7 @@ public bool IsTraceEnabled()

public Exception Trace(Exception exception)
{
_nlogLogger.Trace(exception, CultureInfo.InvariantCulture, exception.Message);
_nlogLogger.Trace(exception);
return exception;
}

Expand Down

0 comments on commit 1d18790

Please sign in to comment.