better instance logging support

This commit is contained in:
alzeih
2010-07-11 18:42:27 +12:00
committed by Paul Chote
parent d0d3f1434e
commit 7d18937415
2 changed files with 18 additions and 10 deletions

View File

@@ -55,19 +55,23 @@ namespace OpenRA
{ {
if (channels.ContainsKey(channelName)) return; if (channels.ContainsKey(channelName)) return;
/* HACK: avoid sharing violations if running multiple instances */ var i = 0;
StreamWriter writer = null; var f = filename;
while (writer == null) while (File.Exists(LogPathPrefix + filename))
{
try try
{ {
writer = File.CreateText(LogPathPrefix + filename); StreamWriter writer = File.CreateText(LogPathPrefix + filename);
writer.AutoFlush = true;
channels.Add(channelName, new ChannelInfo() { Upload = upload, Filename = filename, Writer = writer, Diff = diff });
return;
} }
catch(IOException){ filename = new Random().Next().ToString() + filename; } catch (IOException) { filename = f + ".{0}".F(++i); }
}
//if no logs exist, just make it
StreamWriter w = File.CreateText(LogPathPrefix + filename);
w.AutoFlush = true;
channels.Add(channelName, new ChannelInfo() { Upload = upload, Filename = filename, Writer = w, Diff = diff });
writer.AutoFlush = true;
channels.Add(channelName, new ChannelInfo() { Upload = upload, Filename = filename, Writer = writer, Diff = diff });
} }
public static void Write(string channel, string format, params object[] args) public static void Write(string channel, string format, params object[] args)

View File

@@ -626,7 +626,11 @@ namespace OpenRA
public static void Exit() { quit = true; } public static void Exit() { quit = true; }
public static void Debug(string s) { Chrome.chatWidget.AddLine(Color.White, "Debug", s); } public static void Debug(string s)
{
if (Chrome.chatWidget != null)
Chrome.chatWidget.AddLine(Color.White, "Debug", s);
}
public static void Disconnect() public static void Disconnect()
{ {