/// <summary> /// The actual logging to file procedure, with threading decision handled in the wrapper /// </summary> /// <param name="ex">The exception to log</param> private void actualLogToFile(WPCException ex) { try { if (!loadDocument()) { createDocument(); } if (buffer.Count > 0) { foreach (WPCException bufferedEx in buffer) { this.loadedDoc.Element("GuardianLog").Add(bufferedEx.convertToElement()); } buffer.Clear(); } this.loadedDoc.Element("GuardianLog").Add(ex.convertToElement()); if (ex.isCritical()) { refreshParameterXML(); saveLoadedDoc(); } } #pragma warning disable catch (IsolatedStorageException isoEx) #pragma warning restore { //Some apps will use the isolated storage on startup, preventing logging, so we write the event to a buffer for next time buffer.Add(ex); } }
/// <summary> /// Log an exception object with custom additional information (for instance variable values at the time of the exception), example use in a catch block /// </summary> /// <param name="level">The LogLevel to assign to this message</param> /// <param name="e">The exception object to log</param> /// <param name="comment">Any additional information</param> public void log(LogLevel level, Exception e, String comment) { if ((int)loggerLevel <= (int)level) { WPCException ex = new WPCException(level, e, comment); if (Debugger.IsAttached) { Debug.WriteLine(ex.getDebugOutput()); } if (toFile || level.Equals(LogLevel.critical) || level.Equals(LogLevel.error)) { logToFile(ex); } } }
/// <summary> /// Wrapper for the actual file logging procedure, if a critical caused this error we can't thread the file writing otherwise the application could exit /// </summary> /// <param name="ex">The exception to log</param> private void logToFile(WPCException ex) { if (!ex.isCritical()) { BackgroundWorker thread = new BackgroundWorker(); thread.DoWork += ((obj, e) => { actualLogToFile(ex); }); thread.RunWorkerAsync(); } else { actualLogToFile(ex); } }
/// <summary> /// The actual logging to file procedure, with threading decision handled in the wrapper /// </summary> /// <param name="ex">The exception to log</param> private void actualLogToFile(WPCException ex) { try { if (!loadDocument()) { createDocument(); } if (buffer.Count > 0) { foreach (WPCException bufferedEx in buffer) { this.loadedDoc.Element("WPCLog").Add(bufferedEx.convertToElement()); } buffer.Clear(); } this.loadedDoc.Element("WPCLog").Add(ex.convertToElement()); if (ex.isCritical()) { refreshParameterXML(); saveLoadedDoc(); } } #pragma warning disable catch (IsolatedStorageException isoEx) #pragma warning restore { //Some apps will use the isolated storage on startup, preventing logging, so we write the event to a buffer for next time buffer.Add(ex); } }
/// <summary> /// Log an exception object with custom additional information (for instance variable values at the time of the exception), example use in a catch block /// </summary> /// <param name="level">The LogLevel to assign to this message</param> /// <param name="e">The exception object to log</param> /// <param name="comment">Any additional information</param> public void log(LogLevel level, Exception e, String comment) { if ((int)loggerLevel <= (int)level) { WPCException ex = new WPCException(level, e, comment); if (Debugger.IsAttached) { Debug.WriteLine(ex.getDebugOutput()); } if (toFile || level.Equals(LogLevel.critical)) { logToFile(ex); } } }