public void Log_Exception() { UT_INIT(); Log.AddDebugLogger(); Log.SetDomain("EXCEPT", Scope.Method); Exception testException = new Exception("TestException Message", new Exception("InnerException Message", new Exception("Inner, inner Exception"))); LogTools.Exception(null, Verbosity.Warning, testException, "Logging an exception: "); }
/** ******************************************************************************************** * Opens the file. **********************************************************************************************/ protected void openFile() { try { sw = new StreamWriter(FileName, true); } #pragma warning disable 168 catch (Exception e) { hasIoError = true; #if ALOX_DBG_LOG LogTools.Exception(ALox.InternalDomains, Verbosity.Error, e, "Can not open file: \"" + FileName + "\". Exception follows"); #endif } #pragma warning restore 168 hasIoError = false; }
/** ******************************************************************************************** * Write the given region of the given AString to the destination buffer. * * @param buffer The string to write a portion of. * @param start The start of the portion in \p buffer to write out. * @param length The length of the portion in \p buffer to write out. * @return The IO status (\c true if OK). **********************************************************************************************/ protected override bool logSubstring(AString buffer, int start, int length) { if (!hasIoError) { try { sw.Write(buffer.Buffer(), start, length); } #pragma warning disable 168 catch (Exception e) { hasIoError = true; #if ALOX_DBG_LOG LogTools.Exception(ALox.InternalDomains, Verbosity.Error, e, "Error writing to file: \"" + FileName + "\". Exception follows"); #endif } #pragma warning restore 168 } return(!hasIoError); }
/** ******************************************************************************************** * Closes the file. **********************************************************************************************/ protected void closeFile() { if (hasIoError) { return; } try { sw.Close(); } #pragma warning disable 168 catch (Exception e) { hasIoError = true; #if ALOX_DBG_LOG LogTools.Exception(ALox.InternalDomains, Verbosity.Error, e, "Error closing file: \"" + FileName + "\". Exception follows"); #endif } #pragma warning restore 168 }
public void Tut_Exception() { #if ALOX_DBG_LOG || ALOX_REL_LOG UT_INIT(); Log.SetVerbosity(tutLog = new MemoryLogger("Tutlog"), Verbosity.Warning, "/"); #if ALOX_DBG_LOG ((TextLogger)Log.GetLogger("Tutlog")).MultiLineMsgMode = 4; #endif //! [Tut_Exceptions] Exception testException = new Exception("TestException Message", new Exception("InnerException Message", new Exception("Inner, inner Exception"))); LogTools.Exception("MYDOM", Verbosity.Warning, testException, "Logging an exception: "); //! [Tut_Exceptions] tutLog.MemoryLog.SearchAndReplace("Tutlog", "CONSOLE"); SaveTutorialOutput("Tut_Exceptions.txt", tutLog.MemoryLog); #endif }
/** ******************************************************************************************** * Start a new log line. Appends a new-line character sequence to previously logged lines. * * @param phase Indicates the beginning or end of a log operation. * @return The IO status (\c true if OK). **********************************************************************************************/ protected override bool notifyLogOp(Phase phase) { // write new line if (phase == Phase.End) { try { sw.WriteLine(); } #pragma warning disable 168 catch (Exception e) { hasIoError = true; #if ALOX_DBG_LOG LogTools.Exception(ALox.InternalDomains, Verbosity.Error, e, "Error writing to file: \"" + FileName + "\". Exception follows"); #endif return(false); } #pragma warning restore 168 } // open/close if (!currentlyInMultiLineOp) { if (phase == Phase.Begin) { openFile(); } else { closeFile(); } } return(!hasIoError); }