Skip to content

Commit

Permalink
[Logger] Small cleanup. Implement IDisposable.
Browse files Browse the repository at this point in the history
  • Loading branch information
Helios747 committed Jun 2, 2018
1 parent 569c209 commit de6d327
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
1 change: 1 addition & 0 deletions DolphinBisectTool/Backend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public void Bisect(string boot_title = "")
{
string sb = string.Join(", ", skipped_builds.ToArray());
log.Write("Skipped builds: " + sb);
log.Dispose();
}
UserInput open_url = BisectEvent(test_index, true);

Expand Down
23 changes: 16 additions & 7 deletions DolphinBisectTool/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,34 @@

namespace DolphinBisectTool
{
class Logger
class Logger : IDisposable
{
StreamWriter log_file;
bool disposed = false;


public Logger()
{
log_file = new StreamWriter("log-" + DateTime.Now.ToString("yyyy-MM-dd_hhmmss") + ".txt");
}

~Logger()
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

protected virtual void Dispose(bool disposing)
{
// TODO - figure out why closing the file here throws an exception.
try
if (disposed)
return;

if (disposing)
{
log_file.Close();
}
catch (Exception e)
{
}

disposed = true;
}

public void Write(string s)
Expand Down

0 comments on commit de6d327

Please sign in to comment.