#At file:///C:/work/wex/installer/ based on revid:iggy@mysql.com-20100920205009-qsrdtlu6is23n3z5
203 Reggie Burnett 2010-09-22
lays the groundwork for our new logging system and gives an example of how to use it internally and how a user would attach to the stream with app.config
added:
WexInstaller/Core/Logger.cs
WexInstaller/Core/LoggerListener.cs
modified:
WexInstaller/Core/ProductManager.cs
WexInstaller/Program.cs
WexInstaller/WexInstaller.csproj
WexInstaller/app.config
=== added file 'WexInstaller/Core/Logger.cs'
=== added file 'WexInstaller/Core/Logger.cs'
--- a/WexInstaller/Core/Logger.cs 1970-01-01 00:00:00 +0000
+++ b/WexInstaller/Core/Logger.cs 2010-09-22 22:25:30 +0000
@@ -0,0 +1,31 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Diagnostics;
+
+namespace WexInstaller.Core
+{
+ public class Logger
+ {
+ private static TraceSource source = new TraceSource("mysql-universal-installer");
+ private static LoggerListener listener;
+
+ static Logger()
+ {
+ listener = new LoggerListener();
+ source.Listeners.Add(listener);
+ }
+
+ public static void LogInformation(string message)
+ {
+ source.TraceInformation(message);
+ source.Flush();
+ }
+
+ public static void LogException(Exception ex)
+ {
+ //source.TraceEvent(TraceEventType.
+ }
+ }
+}
=== added file 'WexInstaller/Core/LoggerListener.cs'
--- a/WexInstaller/Core/LoggerListener.cs 1970-01-01 00:00:00 +0000
+++ b/WexInstaller/Core/LoggerListener.cs 2010-09-22 22:25:30 +0000
@@ -0,0 +1,64 @@
+using System.Text;
+using System.IO;
+using System.Diagnostics;
+
+namespace WexInstaller.Core
+{
+ class LoggerListener : TraceListener
+ {
+ private TextWriterTraceListener textFile;
+ private List<string> buffer = new List<string>();
+
+ public override void Write(string message)
+ {
+ CheckTextFile();
+ if (textFile != null)
+ {
+ textFile.Write(message);
+ textFile.Flush();
+ }
+ else
+ buffer.Add(message);
+ }
+
+ public override void WriteLine(string message)
+ {
+ Write(message + Environment.NewLine);
+ }
+
+ private void CheckTextFile()
+ {
+ if (textFile != null ||
+ String.IsNullOrEmpty(InstallerConfiguration.HomeDir)) return;
+
+ string logPath = InstallerConfiguration.HomeDir + "\\Logs";
+ if (!Directory.Exists(logPath))
+ Directory.CreateDirectory(logPath);
+
+ string logFile = String.Format("{0}\\installer.log", logPath);
+ if (File.Exists(logFile))
+ BackupLogFile(logPath, logFile);
+ textFile = new TextWriterTraceListener(logFile);
+ foreach (string msg in buffer)
+ textFile.Write(msg);
+ buffer.Clear();
+ }
+
+ private void BackupLogFile(string logPath, string logFile)
+ {
+ int i = 0;
+ while (true)
+ {
+ string backupFile = String.Format("{0}\\installer_log.{1}", logPath, i);
+ if (!File.Exists(backupFile))
+ {
+ File.Move(logFile, backupFile);
+ break;
+ }
+ i++;
+ }
+ }
+ }
+}
=== modified file 'WexInstaller/Core/ProductManager.cs'
--- a/WexInstaller/Core/ProductManager.cs 2010-09-15 21:17:03 +0000
+++ b/WexInstaller/Core/ProductManager.cs 2010-09-22 22:25:30 +0000
@@ -48,6 +48,8 @@
public static void Load()
{
+ Logger.LogInformation("ProductManager.Load starting");
+
if (File.Exists(InstallerConfiguration.TempManifest))
File.Delete(InstallerConfiguration.TempManifest);
=== modified file 'WexInstaller/Program.cs'
--- a/WexInstaller/Program.cs 2010-08-18 22:27:39 +0000
+++ b/WexInstaller/Program.cs 2010-09-22 22:25:30 +0000
@@ -16,6 +16,8 @@
[STAThread]
static void Main()
{
+ Logger.LogInformation("Installer starting up.");
+
InstallerConfiguration.Load();
Application.EnableVisualStyles();
@@ -26,6 +28,7 @@
Application.Run(new MainForm());
InstallerConfiguration.Save();
+ Logger.LogInformation("Installer exit");
}
/* static bool ProcessCommandLineArguments()
=== modified file 'WexInstaller/WexInstaller.csproj'
--- a/WexInstaller/WexInstaller.csproj 2010-09-15 17:29:29 +0000
+++ b/WexInstaller/WexInstaller.csproj 2010-09-22 22:25:30 +0000
@@ -109,6 +109,8 @@
<DependentUpon>ResourcesPage.cs</DependentUpon>
</Compile>
<Compile Include="Core\Installer.cs" />
+ <Compile Include="Core\Logger.cs" />
+ <Compile Include="Core\LoggerListener.cs" />
<Compile Include="Core\MsiInterop.cs" />
<Compile Include="Core\MysqlSCM.cs">
<SubType>Component</SubType>
=== modified file 'WexInstaller/app.config'
--- a/WexInstaller/app.config 2010-09-17 16:38:02 +0000
+++ b/WexInstaller/app.config 2010-09-22 22:25:30 +0000
@@ -1,3 +1,24 @@
<?xml version="1.0"?>
<configuration>
-<startup><supportedRuntime version="v2.0.50727"/></startup></configuration>
+<startup><supportedRuntime version="v2.0.50727"/></startup>
+
+ <system.diagnostics>
+ <sources>
+ <source name="mysql-universal-installer"
+ switchName="sourceSwitch"
+ switchType="System.Diagnostics.SourceSwitch">
+ <listeners>
+ <add name="text"
+ type="System.Diagnostics.TextWriterTraceListener"
+ initializeData="c:\users\reggie\desktop\Data.log"
+ traceOutputOptions="DateTime">
+ </add>
+ </listeners>
+ </source>
+ </sources>
+ <switches>
+ <add name="sourceSwitch" value="All"/>
+ </switches>
+ </system.diagnostics>
+
+</configuration>
Attachment: [text/bzr-bundle] bzr/reggie.burnett@oracle.com-20100922222530-5mu5e6ipss2d50yw.bundle
| Thread |
|---|
| • bzr commit into wex-installer-1.0 branch (reggie.burnett:203) | Reggie Burnett | 23 Sep |