Mercurial > repos > IBDev-IBBoard.WarFoundry.GUI.WinForms
changeset 68:fd8654afd331
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
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 26 Sep 2009 19:12:04 +0000 |
parents | 75cf9b6608f5 |
children | ff80ed9ac50f |
files | AssemblyInfo.cs FrmMain.cs WarFoundry.exe.log4net |
diffstat | 3 files changed, 29 insertions(+), 25 deletions(-) [+] |
line wrap: on
line diff
--- 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
--- 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); } } }
--- 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 @@ -<?xml version="1.0" encoding="utf-8" ?> <log4net> <appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender"> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%-5p [%d{HH:MM:ss}]: %C{1}.%M() - Line: %L - %m%n" /> </layout> </appender> <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender"> <file value="logs\WarFoundry.log" /> <appendToFile value="false" /> <rollingStyle value="Size" /> <maxSizeRollBackups value="-1" /> <maximumFileSize value="100MB" /> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%-5p [%d{HH:MM:ss}]: %C{1}.%M() - Line: %L - %m%n" /> </layout> </appender> <root> <level value="DEBUG" /> <appender-ref ref="ConsoleAppender" /> <appender-ref ref="RollingLogFileAppender" /> </root> </log4net> \ No newline at end of file +<?xml version="1.0" encoding="utf-8" ?> <log4net> <appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender"> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%-5p [%d{HH:MM:ss}]: %C{1}.%M() - Line: %L - %m%n" /> </layout> </appender> <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender"> <file value="logs\\WarFoundry.log" /> <appendToFile value="false" /> <rollingStyle value="Size" /> <maxSizeRollBackups value="-1" /> <maximumFileSize value="100MB" /> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%-5p [%d{HH:MM:ss}]: %C{1}.%M() - Line: %L - %m%n" /> </layout> </appender> <root> <level value="DEBUG" /> <appender-ref ref="ConsoleAppender" /> <appender-ref ref="RollingLogFileAppender" /> </root> </log4net> \ No newline at end of file