forked from synhershko/NAppUpdate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introducing proper logging capability
- Loading branch information
1 parent
419e5ba
commit 086d2bc
Showing
7 changed files
with
158 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace NAppUpdate.Framework.Common | ||
{ | ||
public class Logger | ||
{ | ||
[Serializable] | ||
public enum SeverityLevel | ||
{ | ||
Debug, | ||
Warning, | ||
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; } | ||
} | ||
|
||
public List<LogItem> LogItems { get; private set; } | ||
|
||
public Logger() | ||
{ | ||
LogItems = new List<LogItem>(); | ||
} | ||
|
||
public Logger(List<LogItem> logItems) | ||
{ | ||
LogItems = logItems; | ||
} | ||
|
||
public void Log(SeverityLevel severity, string message, params object[] args) | ||
{ | ||
LogItems.Add(new LogItem | ||
{ | ||
Message = string.Format(message, args), | ||
Severity = severity, | ||
Timestamp = DateTime.Now, | ||
}); | ||
} | ||
|
||
public void Log(Exception exception) | ||
{ | ||
Log(exception, string.Empty); | ||
} | ||
|
||
public void Log(Exception exception, string message) | ||
{ | ||
LogItems.Add(new LogItem | ||
{ | ||
Message = message, | ||
Severity = SeverityLevel.Error, | ||
Timestamp = DateTime.Now, | ||
Exception = exception, | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.