전체 예외 및 스택 추적 부분 만 표시하고 싶습니다. 현재 예외에 대한 ex.ToString()을 호출하고 있지만 stacktrace 항목이 "중복"되었음을 확인했습니다.예외 스택 트레이스에서 '중복'메소드 이름을 제거하려면 어떻게해야합니까?
내가 생각할 수있는 유일한 점은 라인 #을 무시하고 중복 문자열에 대한 문자열을 구문 분석하는 것입니다. 나는 정규식 패턴을 알아 내야 할 것 같다.
예는 : 스택 트레이스에 "ProcessTeleformFiles.ProcessExpTableRecord이 (..."두 번하지만 서로 다른 라인 #의 's의 나열이
내가 쓰는 거의 모든 단일 C# 4.0의 방법으로 시도의 catch 블록을 사용합니다.. 나는 사용자 지정 오류를 제기하고자 할 때
try
catch (Exception)
{
throw;
}
그리고는 나는 기본적으로 표시 및/또는과 같이 오류 로그 코드의 루트 레벨에서 다음이
try
catch (Exception ex)
{
throw new Exception("my custom message", ex);
}
을 수행합니다
try
catch (Exception ex)
{
MessageBox.Show("Exception found: " + ex.ToString();
}
스택 트레이스는 다음과 같이 할 수 그러나 :
Error was logged: Error in ProcessExp() method.
Exception found: System.Exception: Error found in Database: C:\MyDatabase.mdb
---> System.Exception: Error found in Table: MyTable
---> System.Exception: Error found in TableID: 1
---> System.Data.OleDb.OleDbException: Could not find output table 'testtable'.
at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr)
at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method)
at System.Data.OleDb.OleDbCommand.ExecuteScalar()
at MiscOleDbFns.Querys.RunExecuteScaler(OleDbConnection Conn, String QueryString, Object[] ParamValues) in C:\Document Files\DotNet common libraries\src 4.0\misclibrary_src\source\MiscOleDbFns.cs:line 247
at MiscOleDbFns.Querys.RunExecuteScalerAndGetAutoNumFromQuery(OleDbConnection Conn, String QueryString, Object[] ParamValues) in C:\Document Files\DotNet common libraries\src 4.0\misclibrary_src\source\MiscOleDbFns.cs:line 271
at ProcessTeleformFiles.InsertExpSummaryFilesRec(OleDbConnection Conn, Boolean LogFile, RcdExpSummaryFiles Rcd) in C:\Document Files\Projects and notes\VS 2010\Projects\OrganizeTeleformFiles\source\OrganizeTeleformFiles\ProcessFiles.cs:line 622
at ProcessTeleformFiles.FindFileInList(OleDbConnection conSystemDB, String sCopyToDBFolderExp, Boolean isLogFile, Boolean isCopyFile, Boolean isDeleteFile, RcdExpSummaryFiles recExpSummaryFiles, Dictionary`2 myList) in C:\Document Files\Projects and notes\VS 2010\Projects\OrganizeTeleformFiles\source\OrganizeTeleformFiles\ProcessFiles.cs:line 1216
at ProcessTeleformFiles.ProcessExpTableRecordSusFiles(OleDbConnection conSystemDB, String sCopyToDBFolderExp, OleDbDataReader Read, RcdSchemaFlds recSchemaFlds, RcdExpSummary recExpSummary, String& tct) in C:\Document Files\Projects and notes\VS 2010\Projects\OrganizeTeleformFiles\source\OrganizeTeleformFiles\ProcessFiles.cs:line 1257
at ProcessTeleformFiles.ProcessExpTableRecord(OleDbConnection conSystemDB, String sCopyToDBFolderExp, OleDbDataReader Read, RcdSchemaFlds recSchemaFlds, RcdExpSummary recExpSummary) in C:\Document Files\Projects and notes\VS 2010\Projects\OrganizeTeleformFiles\source\OrganizeTeleformFiles\ProcessFiles.cs:line 965
--- End of inner exception stack trace ---
at ProcessTeleformFiles.ProcessExpTableRecord(OleDbConnection conSystemDB, String sCopyToDBFolderExp, OleDbDataReader Read, RcdSchemaFlds recSchemaFlds, RcdExpSummary recExpSummary) in C:\Document Files\Projects and notes\VS 2010\Projects\OrganizeTeleformFiles\source\OrganizeTeleformFiles\ProcessFiles.cs:line 982
at ProcessTeleformFiles.ProcessExpDatabaseTable(OleDbConnection conSystemDB, OleDbConnection ConnExpDb, String sCopyToDBFolderExp, String mdbPath, String sTable, BackgroundWorker worker, DoWorkEventArgs workerEvents) in C:\Document Files\Projects and notes\VS 2010\Projects\OrganizeTeleformFiles\source\OrganizeTeleformFiles\ProcessFiles.cs:line 242
--- End of inner exception stack trace ---
at ProcessTeleformFiles.ProcessExpDatabaseTable(OleDbConnection conSystemDB, OleDbConnection ConnExpDb, String sCopyToDBFolderExp, String mdbPath, String sTable, BackgroundWorker worker, DoWorkEventArgs workerEvents) in C:\Document Files\Projects and notes\VS 2010\Projects\OrganizeTeleformFiles\source\OrganizeTeleformFiles\ProcessFiles.cs:line 250
at ProcessTeleformFiles.ProcessExpDatabase(OleDbConnection conSystemDB, String mdbPath, BackgroundWorker worker, DoWorkEventArgs workerEvents) in C:\Document Files\Projects and notes\VS 2010\Projects\OrganizeTeleformFiles\source\OrganizeTeleformFiles\ProcessFiles.cs:line 161
--- End of inner exception stack trace ---
at ProcessTeleformFiles.ProcessExpDatabase(OleDbConnection conSystemDB, String mdbPath, BackgroundWorker worker, DoWorkEventArgs workerEvents) in C:\Document Files\Projects and notes\VS 2010\Projects\OrganizeTeleformFiles\source\OrganizeTeleformFiles\ProcessFiles.cs:line 174
at ProcessTeleformFiles.ProcessExp(BackgroundWorker worker, DoWorkEventArgs workerEvents) in C:\Document Files\Projects and notes\VS 2010\Projects\OrganizeTeleformFiles\source\OrganizeTeleformFiles\ProcessFiles.cs:line 74
내가 중복 메시지가하지 않는 오류 메시지를 원하는 반면, 이 같은 더 많은 :
Error was logged: Error in ProcessExp() method.
Exception found: System.Exception: Error found in Database: C:\MyDatabase.mdb
---> System.Exception: Error found in Table: MyTable
---> System.Exception: Error found in TableID: 1
---> System.Data.OleDb.OleDbException: Could not find output table 'testtable'.
at MiscOleDbFns.Querys.RunExecuteScaler(OleDbConnection Conn, String QueryString, Object[] ParamValues) in C:\Document Files\DotNet common libraries\src 4.0\misclibrary_src\source\MiscOleDbFns.cs:line 247
at MiscOleDbFns.Querys.RunExecuteScalerAndGetAutoNumFromQuery(OleDbConnection Conn, String QueryString, Object[] ParamValues) in C:\Document Files\DotNet common libraries\src 4.0\misclibrary_src\source\MiscOleDbFns.cs:line 271
at ProcessTeleformFiles.InsertExpSummaryFilesRec(OleDbConnection Conn, Boolean LogFile, RcdExpSummaryFiles Rcd) in C:\Document Files\Projects and notes\VS 2010\Projects\OrganizeTeleformFiles\source\OrganizeTeleformFiles\ProcessFiles.cs:line 622
at ProcessTeleformFiles.FindFileInList(OleDbConnection conSystemDB, String sCopyToDBFolderExp, Boolean isLogFile, Boolean isCopyFile, Boolean isDeleteFile, RcdExpSummaryFiles recExpSummaryFiles, Dictionary`2 myList) in C:\Document Files\Projects and notes\VS 2010\Projects\OrganizeTeleformFiles\source\OrganizeTeleformFiles\ProcessFiles.cs:line 1216
at ProcessTeleformFiles.ProcessExpTableRecordSusFiles(OleDbConnection conSystemDB, String sCopyToDBFolderExp, OleDbDataReader Read, RcdSchemaFlds recSchemaFlds, RcdExpSummary recExpSummary, String& tct) in C:\Document Files\Projects and notes\VS 2010\Projects\OrganizeTeleformFiles\source\OrganizeTeleformFiles\ProcessFiles.cs:line 1257
at ProcessTeleformFiles.ProcessExpTableRecord(OleDbConnection conSystemDB, String sCopyToDBFolderExp, OleDbDataReader Read, RcdSchemaFlds recSchemaFlds, RcdExpSummary recExpSummary) in C:\Document Files\Projects and notes\VS 2010\Projects\OrganizeTeleformFiles\source\OrganizeTeleformFiles\ProcessFiles.cs:line 965
at ProcessTeleformFiles.ProcessExpDatabaseTable(OleDbConnection conSystemDB, OleDbConnection ConnExpDb, String sCopyToDBFolderExp, String mdbPath, String sTable, BackgroundWorker worker, DoWorkEventArgs workerEvents) in C:\Document Files\Projects and notes\VS 2010\Projects\OrganizeTeleformFiles\source\OrganizeTeleformFiles\ProcessFiles.cs:line 242
at ProcessTeleformFiles.ProcessExpDatabase(OleDbConnection conSystemDB, String mdbPath, BackgroundWorker worker, DoWorkEventArgs workerEvents) in C:\Document Files\Projects and notes\VS 2010\Projects\OrganizeTeleformFiles\source\OrganizeTeleformFiles\ProcessFiles.cs:line 161
at ProcessTeleformFiles.ProcessExp(BackgroundWorker worker, DoWorkEventArgs workerEvents) in C:\Document Files\Projects and notes\VS 2010\Projects\OrganizeTeleformFiles\source\OrganizeTeleformFiles\ProcessFiles.cs:line 74
UPDATE : 그래서 돌아 오는 길에 , 내 코드에서 모든 시도 어획량을 제거했다. stacktrace를 수정하는 유일한 상황은 사용자에게 좀 더 사용자 친화적 인 단순화 된 출력을 제공하는 한 곳에서입니다. 내부적으로 항상 전체 스택을 기록합니다. 모두에게 감사드립니다!
무엇을하려고합니까? 이들은 '중복'하지 않습니다. 스택의 현재 프레임입니다. 왜 이걸하고 싶어? – linuxuser27
메시지 문자열이 더 짧아지고 더 읽기 쉽고 유용 할 것으로 생각하기 때문에. – user610064
왜 더 짧게하고 싶습니까? 짧아지면 불완전 해져서 문제의 원인을 찾기가 더 어려워집니다! –