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 diff
     1.1 --- a/AssemblyInfo.cs	Sat Sep 26 11:18:13 2009 +0000
     1.2 +++ b/AssemblyInfo.cs	Sat Sep 26 19:12:04 2009 +0000
     1.3 @@ -60,3 +60,5 @@
     1.4  [assembly: AssemblyDelaySign(false)]
     1.5  [assembly: AssemblyKeyFile("")]
     1.6  [assembly: AssemblyKeyName("")]
     1.7 +
     1.8 +[assembly: log4net.Config.XmlConfigurator(ConfigFileExtension = "log4net", Watch = true)]
     1.9 \ No newline at end of file
     2.1 --- a/FrmMain.cs	Sat Sep 26 11:18:13 2009 +0000
     2.2 +++ b/FrmMain.cs	Sat Sep 26 19:12:04 2009 +0000
     2.3 @@ -39,7 +39,7 @@
     2.4          const string DefaultDataDir = "data";
     2.5  
     2.6  		private Preferences preferences;
     2.7 -		protected readonly ILog logger = LogManager.GetLogger(typeof(FrmMain));
     2.8 +		private readonly ILog log = LogManager.GetLogger(typeof(FrmMain));
     2.9  
    2.10  		private CommandStack commandStack;
    2.11  		private ToolBarButton[] categoryButtons;
    2.12 @@ -99,8 +99,10 @@
    2.13  		{
    2.14  			try
    2.15  			{
    2.16 +				LogManager.GetLogger(typeof(FrmMain)).Info("Starting WarFoundry WinForms");
    2.17  				Application.EnableVisualStyles();
    2.18  				Application.Run(new FrmMain(args));
    2.19 +				LogManager.GetLogger(typeof(FrmMain)).Info("Closing WarFoundry WinForms");
    2.20  			}
    2.21  			catch (Exception ex)
    2.22  			{
    2.23 @@ -123,7 +125,7 @@
    2.24  			}
    2.25  			catch (TranslationLoadException ex)
    2.26  			{
    2.27 -				logger.Error(ex);
    2.28 +				log.Error("Translation loading failed for language " + Preferences["language"].ToString(), ex);
    2.29  				MessageBox.Show(this, "Translation loading failed for language " + Preferences["language"].ToString(), "Translation failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
    2.30  			}
    2.31  
    2.32 @@ -546,7 +548,7 @@
    2.33  		{
    2.34  			foreach (FileLoadFailure failure in failures)
    2.35  			{
    2.36 -				logger.Warn("Failed to load " + failure.FailedFile.FullName + ": " + failure.Message);
    2.37 +				log.Warn("Failed to load " + failure.FailedFile.FullName + ": " + failure.Message);
    2.38  			}
    2.39  		}
    2.40  
    2.41 @@ -576,38 +578,38 @@
    2.42  
    2.43  		private bool OpenArmy()
    2.44  		{
    2.45 -			if (CloseCurrentArmy())
    2.46 +			if (openArmyDialog.Filter=="")
    2.47  			{
    2.48 -				if (openArmyDialog.Filter=="")
    2.49 +				string savePath = ArmiesPath;
    2.50 +			
    2.51 +				if (!Directory.Exists(savePath))
    2.52  				{
    2.53 -					string savePath = ArmiesPath;
    2.54 -				
    2.55 -					if (!Directory.Exists(savePath))
    2.56 -					{
    2.57 -						Directory.CreateDirectory(savePath);
    2.58 -					}
    2.59 -
    2.60 -					openArmyDialog.InitialDirectory = savePath;
    2.61 -					openArmyDialog.Filter = Translation.GetTranslation("armyFileFilter")+"|*.army";
    2.62 -					openArmyDialog.Title = Translation.GetTranslation("openArmyDialog");
    2.63 -
    2.64 +					Directory.CreateDirectory(savePath);
    2.65  				}
    2.66  
    2.67 -				DialogResult dr = openArmyDialog.ShowDialog(this);
    2.68 +				openArmyDialog.InitialDirectory = savePath;
    2.69 +				openArmyDialog.Filter = Translation.GetTranslation("armyFileFilter")+"|*.army";
    2.70 +				openArmyDialog.Title = Translation.GetTranslation("openArmyDialog");
    2.71  
    2.72 -				if (dr == DialogResult.OK)
    2.73 +			}
    2.74 +
    2.75 +			DialogResult dr = openArmyDialog.ShowDialog(this);
    2.76 +
    2.77 +			if (dr == DialogResult.OK)
    2.78 +			{
    2.79 +				if (CloseCurrentArmy())
    2.80  				{
    2.81  					try
    2.82  					{
    2.83  						string newFilePath = openArmyDialog.FileName;
    2.84  						CurrentArmy = WarFoundryLoader.GetDefault().LoadArmy(new FileInfo(newFilePath));
    2.85  						loadedFilePath = newFilePath;
    2.86 -						return true;					
    2.87 +						return true;
    2.88  					}
    2.89  					catch (InvalidFileException ex)
    2.90  					{
    2.91 -						logger.Error(ex);
    2.92 -						MessageBox.Show(this, ex.Message, Translation.GetTranslation("InvalidFileBoxTitle", "Invalid data file"), MessageBoxButtons.OK, MessageBoxIcon.Error);
    2.93 +						log.Error(ex);
    2.94 +						MessageBox.Show(this, ex.Message, Translation.GetTranslation("InvalidFileBoxTitle", "Invalid army file"), MessageBoxButtons.OK, MessageBoxIcon.Error);
    2.95  						return false;
    2.96  					}
    2.97  				}
    2.98 @@ -1266,7 +1268,7 @@
    2.99  			{
   2.100  				Army army = CurrentArmy;
   2.101  				string filePath = dialog.FileName;
   2.102 -				logger.DebugFormat("Exporting {0} to {1} as basic HTML", army.Name, filePath);
   2.103 +				log.DebugFormat("Exporting {0} to {1} as basic HTML", army.Name, filePath);
   2.104  				WarFoundryHtmlExporter.GetDefault().ExportArmy(army, filePath);
   2.105  			}
   2.106  		}
   2.107 @@ -1277,13 +1279,13 @@
   2.108  
   2.109  			if (gameSystemID != null && !"".Equals(gameSystemID))
   2.110  			{
   2.111 -				logger.Debug("Attempting to load current game system from properties");
   2.112 +				log.Debug("Attempting to load current game system from properties");
   2.113  				GameSystem sys = WarFoundryLoader.GetDefault().GetGameSystem(gameSystemID);
   2.114  
   2.115  				if (sys != null)
   2.116  				{
   2.117  					WarFoundryCore.CurrentGameSystem = sys;
   2.118 -					logger.InfoFormat("Loaded game system {0} from properties", gameSystemID);
   2.119 +					log.InfoFormat("Loaded game system {0} from properties", gameSystemID);
   2.120  				}
   2.121  			}
   2.122  		}
     3.1 --- a/WarFoundry.exe.log4net	Sat Sep 26 11:18:13 2009 +0000
     3.2 +++ b/WarFoundry.exe.log4net	Sat Sep 26 19:12:04 2009 +0000
     3.3 @@ -1,1 +1,1 @@
     3.4 -<?xml version="1.0" encoding="utf-8" ?>
     3.5 <log4net>
     3.6 	<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
     3.7 		<layout type="log4net.Layout.PatternLayout">
     3.8 			<conversionPattern value="%-5p [%d{HH:MM:ss}]: %C{1}.%M() - Line: %L - %m%n" />
     3.9 		</layout>
    3.10 	</appender>
    3.11 	<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
    3.12 		<file value="logs\WarFoundry.log" />
    3.13 		<appendToFile value="false" />
    3.14 		<rollingStyle value="Size" />
    3.15 		<maxSizeRollBackups value="-1" />
    3.16 		<maximumFileSize value="100MB" />
    3.17 		<layout type="log4net.Layout.PatternLayout">
    3.18 			<conversionPattern value="%-5p [%d{HH:MM:ss}]: %C{1}.%M() - Line: %L - %m%n" />
    3.19 		</layout>
    3.20 	</appender>
    3.21 	<root>
    3.22 		<level value="DEBUG" />
    3.23 		<appender-ref ref="ConsoleAppender" />
    3.24 		<appender-ref ref="RollingLogFileAppender" />
    3.25 	</root>
    3.26 </log4net>
    3.27 
    3.28 \ No newline at end of file
    3.29 +<?xml version="1.0" encoding="utf-8" ?>
    3.30 <log4net>
    3.31 	<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
    3.32 		<layout type="log4net.Layout.PatternLayout">
    3.33 			<conversionPattern value="%-5p [%d{HH:MM:ss}]: %C{1}.%M() - Line: %L - %m%n" />
    3.34 		</layout>
    3.35 	</appender>
    3.36 	<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
    3.37 		<file value="logs\\WarFoundry.log" />
    3.38 		<appendToFile value="false" />
    3.39 		<rollingStyle value="Size" />
    3.40 		<maxSizeRollBackups value="-1" />
    3.41 		<maximumFileSize value="100MB" />
    3.42 		<layout type="log4net.Layout.PatternLayout">
    3.43 			<conversionPattern value="%-5p [%d{HH:MM:ss}]: %C{1}.%M() - Line: %L - %m%n" />
    3.44 		</layout>
    3.45 	</appender>
    3.46 	<root>
    3.47 		<level value="DEBUG" />
    3.48 		<appender-ref ref="ConsoleAppender" />
    3.49 		<appender-ref ref="RollingLogFileAppender" />
    3.50 	</root>
    3.51 </log4net>
    3.52 
    3.53 \ No newline at end of file