Browse Source

Merge pull request #121 from sinsinpub/log_timestamp

Logging timestamp
tags/3.2
clowwindy 10 years ago
parent
commit
b646b41c81
2 changed files with 27 additions and 3 deletions
  1. +26
    -2
      shadowsocks-csharp/Controller/Logging.cs
  2. +1
    -1
      shadowsocks-csharp/Controller/UpdateChecker.cs

+ 26
- 2
shadowsocks-csharp/Controller/Logging.cs View File

@@ -17,8 +17,7 @@ namespace Shadowsocks.Controller
string temppath = Path.GetTempPath(); string temppath = Path.GetTempPath();
LogFile = Path.Combine(temppath, "shadowsocks.log"); LogFile = Path.Combine(temppath, "shadowsocks.log");
FileStream fs = new FileStream(LogFile, FileMode.Append); FileStream fs = new FileStream(LogFile, FileMode.Append);
TextWriter tmp = Console.Out;
StreamWriter sw = new StreamWriter(fs);
StreamWriterWithTimestamp sw = new StreamWriterWithTimestamp(fs);
sw.AutoFlush = true; sw.AutoFlush = true;
Console.SetOut(sw); Console.SetOut(sw);
Console.SetError(sw); Console.SetError(sw);
@@ -61,5 +60,30 @@ namespace Shadowsocks.Controller
Console.WriteLine(e); Console.WriteLine(e);
} }
} }
}
// Simply extended System.IO.StreamWriter for adding timestamp workaround
public class StreamWriterWithTimestamp : StreamWriter
{
public StreamWriterWithTimestamp(Stream stream) : base(stream)
{
}
private string GetTimestamp()
{
return "[" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "] ";
}
public override void WriteLine(string value)
{
base.WriteLine(GetTimestamp() + value);
}
public override void Write(string value)
{
base.Write(GetTimestamp() + value);
}
} }
} }

+ 1
- 1
shadowsocks-csharp/Controller/UpdateChecker.cs View File

@@ -145,7 +145,7 @@ namespace Shadowsocks.Controller
} }
catch (Exception ex) catch (Exception ex)
{ {
Console.Write(ex.ToString());
Console.WriteLine(ex.ToString());
return; return;
} }
} }


Loading…
Cancel
Save