# HG changeset patch # User IBBoard # Date 1253992324 0 # Node ID fd8654afd331a79fcf777b4f291052c18a504e8c # Parent 75cf9b6608f5d7d21dda091d8d4d4160f1a77c74 Fixes #183: Get logging working with WinForms * Add required line to AssemblyInfo.cs * Tidy up logging in FrmMain and make sure that we have startup and shutdown messages diff -r 75cf9b6608f5 -r fd8654afd331 AssemblyInfo.cs --- a/AssemblyInfo.cs Sat Sep 26 11:18:13 2009 +0000 +++ b/AssemblyInfo.cs Sat Sep 26 19:12:04 2009 +0000 @@ -60,3 +60,5 @@ [assembly: AssemblyDelaySign(false)] [assembly: AssemblyKeyFile("")] [assembly: AssemblyKeyName("")] + +[assembly: log4net.Config.XmlConfigurator(ConfigFileExtension = "log4net", Watch = true)] \ No newline at end of file diff -r 75cf9b6608f5 -r fd8654afd331 FrmMain.cs --- a/FrmMain.cs Sat Sep 26 11:18:13 2009 +0000 +++ b/FrmMain.cs Sat Sep 26 19:12:04 2009 +0000 @@ -39,7 +39,7 @@ const string DefaultDataDir = "data"; private Preferences preferences; - protected readonly ILog logger = LogManager.GetLogger(typeof(FrmMain)); + private readonly ILog log = LogManager.GetLogger(typeof(FrmMain)); private CommandStack commandStack; private ToolBarButton[] categoryButtons; @@ -99,8 +99,10 @@ { try { + LogManager.GetLogger(typeof(FrmMain)).Info("Starting WarFoundry WinForms"); Application.EnableVisualStyles(); Application.Run(new FrmMain(args)); + LogManager.GetLogger(typeof(FrmMain)).Info("Closing WarFoundry WinForms"); } catch (Exception ex) { @@ -123,7 +125,7 @@ } catch (TranslationLoadException ex) { - logger.Error(ex); + log.Error("Translation loading failed for language " + Preferences["language"].ToString(), ex); MessageBox.Show(this, "Translation loading failed for language " + Preferences["language"].ToString(), "Translation failure", MessageBoxButtons.OK, MessageBoxIcon.Error); } @@ -546,7 +548,7 @@ { foreach (FileLoadFailure failure in failures) { - logger.Warn("Failed to load " + failure.FailedFile.FullName + ": " + failure.Message); + log.Warn("Failed to load " + failure.FailedFile.FullName + ": " + failure.Message); } } @@ -576,38 +578,38 @@ private bool OpenArmy() { - if (CloseCurrentArmy()) + if (openArmyDialog.Filter=="") { - if (openArmyDialog.Filter=="") + string savePath = ArmiesPath; + + if (!Directory.Exists(savePath)) { - string savePath = ArmiesPath; - - if (!Directory.Exists(savePath)) - { - Directory.CreateDirectory(savePath); - } - - openArmyDialog.InitialDirectory = savePath; - openArmyDialog.Filter = Translation.GetTranslation("armyFileFilter")+"|*.army"; - openArmyDialog.Title = Translation.GetTranslation("openArmyDialog"); - + Directory.CreateDirectory(savePath); } - DialogResult dr = openArmyDialog.ShowDialog(this); + openArmyDialog.InitialDirectory = savePath; + openArmyDialog.Filter = Translation.GetTranslation("armyFileFilter")+"|*.army"; + openArmyDialog.Title = Translation.GetTranslation("openArmyDialog"); + + } - if (dr == DialogResult.OK) + DialogResult dr = openArmyDialog.ShowDialog(this); + + if (dr == DialogResult.OK) + { + if (CloseCurrentArmy()) { try { string newFilePath = openArmyDialog.FileName; CurrentArmy = WarFoundryLoader.GetDefault().LoadArmy(new FileInfo(newFilePath)); loadedFilePath = newFilePath; - return true; + return true; } catch (InvalidFileException ex) { - logger.Error(ex); - MessageBox.Show(this, ex.Message, Translation.GetTranslation("InvalidFileBoxTitle", "Invalid data file"), MessageBoxButtons.OK, MessageBoxIcon.Error); + log.Error(ex); + MessageBox.Show(this, ex.Message, Translation.GetTranslation("InvalidFileBoxTitle", "Invalid army file"), MessageBoxButtons.OK, MessageBoxIcon.Error); return false; } } @@ -1266,7 +1268,7 @@ { Army army = CurrentArmy; string filePath = dialog.FileName; - logger.DebugFormat("Exporting {0} to {1} as basic HTML", army.Name, filePath); + log.DebugFormat("Exporting {0} to {1} as basic HTML", army.Name, filePath); WarFoundryHtmlExporter.GetDefault().ExportArmy(army, filePath); } } @@ -1277,13 +1279,13 @@ if (gameSystemID != null && !"".Equals(gameSystemID)) { - logger.Debug("Attempting to load current game system from properties"); + log.Debug("Attempting to load current game system from properties"); GameSystem sys = WarFoundryLoader.GetDefault().GetGameSystem(gameSystemID); if (sys != null) { WarFoundryCore.CurrentGameSystem = sys; - logger.InfoFormat("Loaded game system {0} from properties", gameSystemID); + log.InfoFormat("Loaded game system {0} from properties", gameSystemID); } } } diff -r 75cf9b6608f5 -r fd8654afd331 WarFoundry.exe.log4net --- a/WarFoundry.exe.log4net Sat Sep 26 11:18:13 2009 +0000 +++ b/WarFoundry.exe.log4net Sat Sep 26 19:12:04 2009 +0000 @@ -1,1 +1,1 @@ - \ No newline at end of file + \ No newline at end of file