Skip to content

Commit

Permalink
Proper exception printout
Browse files Browse the repository at this point in the history
  • Loading branch information
synhershko committed Jul 13, 2012
1 parent bf09759 commit 0d984d7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
11 changes: 11 additions & 0 deletions src/NAppUpdate.Framework/Common/Exceptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ public NAppUpdateException() : base() { }
public NAppUpdateException(string message) : base(message) { }
public NAppUpdateException(string message, Exception ex) : base(message, ex) { }
public NAppUpdateException(SerializationInfo info, StreamingContext context) : base(info, context) { }

public override string ToString()
{
var ret = Message;
if (!string.IsNullOrEmpty(ret)) ret += Environment.NewLine;
if (InnerException != null)
ret += InnerException;
else
ret += StackTrace;
return ret;
}
}

[Serializable]
Expand Down
30 changes: 22 additions & 8 deletions src/NAppUpdate.Framework/Common/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,28 @@ public enum SeverityLevel
Error
}

[Serializable]
public class LogItem
{
public DateTime Timestamp { get; set; }
public string Message { get; set; }
public Exception Exception { get; set; }
public SeverityLevel Severity { get; set; }
}
[Serializable]
public class LogItem
{
public DateTime Timestamp { get; set; }
public string Message { get; set; }
public Exception Exception { get; set; }
public SeverityLevel Severity { get; set; }

public override string ToString()
{
if (Exception == null)
return string.Format("{0,-25}\t{1}\t{2}",
Timestamp.ToShortDateString() + " " + Timestamp.ToString("HH:mm:ss.fff"),
Severity,
Message);

return string.Format("{0,-25}\t{1}\t{2}{3}{4}",
Timestamp.ToShortDateString() + " " + Timestamp.ToString("HH:mm:ss.fff"),
Severity,
Message, Environment.NewLine, Exception);
}
}

public List<LogItem> LogItems { get; private set; }

Expand Down

0 comments on commit 0d984d7

Please sign in to comment.