/// <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> /// 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); } }