-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add error logging feature while converting
- Loading branch information
Showing
4 changed files
with
85 additions
and
22 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Osu2Saber.Model | ||
{ | ||
class Logger | ||
{ | ||
List<ErrorInfo> errors; | ||
string fileName; | ||
|
||
public Logger() | ||
{ | ||
errors = new List<ErrorInfo>(); | ||
fileName = $"Log_{DateTime.Now.ToString("yyyyMMddHHmmss")}.txt"; | ||
} | ||
|
||
public void AddException(Exception e, string filePath) | ||
{ | ||
lock (errors) | ||
{ | ||
var error = new ErrorInfo { Exception = e, ArchiveName = Path.GetFileName(filePath) }; | ||
errors.Add(error); | ||
} | ||
} | ||
|
||
public void Write() | ||
{ | ||
lock (errors) | ||
{ | ||
using (var writer = new StreamWriter(fileName, true)) | ||
{ | ||
writer.Write(BuildErrorString()); | ||
} | ||
errors.Clear(); | ||
} | ||
} | ||
|
||
string BuildErrorString() | ||
{ | ||
var sb = new StringBuilder(); | ||
foreach (var error in errors) | ||
{ | ||
sb.Append($"Error while converting - {error.ArchiveName}\n"); | ||
sb.Append(error.Exception.ToString()); | ||
sb.Append("\n\n"); | ||
} | ||
return sb.ToString(); | ||
} | ||
|
||
class ErrorInfo | ||
{ | ||
public Exception Exception; | ||
public string ArchiveName; | ||
} | ||
} | ||
} |
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