=== modified file 'XWikiLib/Logging/Log.cs' --- XWikiLib/Logging/Log.cs 2010-02-15 17:15:38 +0000 +++ XWikiLib/Logging/Log.cs 2010-12-10 08:46:18 +0000 @@ -40,8 +40,11 @@ private static string logName = "XOffice"; private static LogMode mode = LogMode.WindowsLog; private static bool fileCreated = false; + + private static bool cant_log = false; + //The message for EventLog can not exceed 32766 bytes - private const int MAX_MSG_SIZE = 32766; + private const int MAX_MSG_SIZE = 32766; /// /// Writes a entry to the appWindows logging system. @@ -53,14 +56,16 @@ try { String msg = (message.Length > MAX_MSG_SIZE) ? message.Substring(0, MAX_MSG_SIZE) : message; - if (EventLog.Exists(logName)) - { + if (!EventLog.Exists(logName)) EventLog.CreateEventSource(eventSource, logName); - } - else - { - EventLog.WriteEntry(eventSource, msg, type); - } + EventLog.WriteEntry(eventSource, msg, type); + } + catch (System.Security.SecurityException e) + { + // can't CreateEventSource() in Vista/Win7 without permissions, + // it has to be done in the installer with Admin privileges + mode = LogMode.FileLog; + WriteFileLog(message, type); } catch (InvalidOperationException ex) { @@ -71,22 +76,36 @@ public static void WriteFileLog(String message, EventLogEntryType type) { - string logFileName = "xoffice.log"; + // no need to check for this in WriteWindowsLog(), as this is our fallback + if (cant_log) + return; + + string logFileName = System.IO.Path.GetTempPath() + "xoffice.log"; FileInfo logFile = new FileInfo(logFileName); - StreamWriter writer = null; - if (!fileCreated) - { - if (logFile.Exists) - { - writer = logFile.AppendText(); - } - else - { - writer = logFile.CreateText(); - } - } - writer.WriteLine(type.ToString() + ": "+ message); - writer.Close(); + try + { + StreamWriter writer = null; + if (!fileCreated) + { + if (logFile.Exists) + { + writer = logFile.AppendText(); + } + else + { + writer = logFile.CreateText(); + } + } + writer.WriteLine(type.ToString() + ": " + message); + writer.Close(); + } + catch (Exception e) + { + cant_log = true; + UserNotifier.Error("Unable to log to the Systems log or" + Environment.NewLine + + "to my fallback option: " + logFile.FullName + Environment.NewLine + + "Please try reinstalling XOffice"); + } } public static void Write(String message, EventLogEntryType type)