拥有以下日志:
2014-02-13 16:06:52,226 [8] ERROR solucao.projeto.arquivo - AutenticarUsuario
System.Threading.ThreadAbortException: O thread estava sendo anulado.
em System.Threading.Thread.AbortInternal()
em System.Threading.Thread.Abort(Object stateInfo)
em System.Web.HttpResponse.End()
2014-02-13 16:06:52,226 [8] ERROR solucao.projeto.arquivo - AutenticarUsuario
System.Threading.ThreadAbortException: O thread estava sendo anulado.
em System.Threading.Thread.AbortInternal()
em System.Threading.Thread.Abort(Object stateInfo)
em System.Web.HttpResponse.End()
尝试使用正则表达式进行恢复,我无法检索属于异常的全文。
(?<data>\d{4}\-\d{2}\-\d{2}\s\d{2}\:\d{2}\:\d{2}\,\d{3})\s\[(?<thread>[0-9]+)\]\s(?<nivel>[A-Z]+)\s(?<classe>([A-Za-z]+\.)+[A-Za-z]+)\s\-\s(?<metodo>[A-Za-z_]+)\n(?<message>.+)
如何恢复完整的例外?
答案 0 :(得分:1)
不确定您的个人捕获,但这样的事情应该起作用
# @"(?ms)^(?<data>[^\[\]\r\n]+)[ \t]+\[(?<thread>[0-9]+)\][ \t]+(?<nivel>[A-Z]+)[ \t]+(?<classe>(?:[A-Za-z]+\.)+[A-Za-z]+)[ \t]+-[ \t]+(?<message>(?:(?!^[^\[\]\r\n]+[ \t]+\[[0-9]+\]).)+)"
(?ms) # Multi-line, Dot-All
^ # Beginning of line
(?<data> [^\[\]\r\n]+ ) # (1), Date/time
[ \t]+ # Horizontal whitespace ( could use '\h' instead )
\[ # '['
(?<thread> [0-9]+ ) # (2), Thread number
\] # ']'
[ \t]+ # Horizontal whitespace
(?<nivel> [A-Z]+ ) # (3), Error
[ \t]+ # Horizontal whitespace
(?<classe> # (4 start), Class
(?: [A-Za-z]+ \. )+
[A-Za-z]+
) # (4 end)
[ \t]+ # Horizontal whitespace
- # '-'
[ \t]+ # Horizontal whitespace
(?<message> # (5 start), Message
(?: # Cluster group
(?! # Lookahead
^ # Not the start of a new exception
[^\[\]\r\n]+ # ( basically, not the above code )
[ \t]+
\[
[0-9]+
\]
) # End Lookahead
. # Continue to grab characters
)+ # End Cluster group, do 1 or more times
) # (5 end)
编辑(删除了Perl测试用例。添加了C#测试用例)
C#测试用例
string sLog =
@"
2014-02-13 16:06:52,226 [8] ERROR solucao.projeto.arquivo - AutenticarUsuario
System.Threading.ThreadAbortException: O thread estava sendo anulado.
em System.Threading.Thread.AbortInternal()
em System.Threading.Thread.Abort(Object stateInfo)
em System.Web.HttpResponse.End()
2014-02-13 16:06:52,226 [8] ERROR solucao.projeto.arquivo - AutenticarUsuario
System.Threading.ThreadAbortException: O thread estava sendo anulado.
em System.Threading.Thread.AbortInternal()
em System.Threading.Thread.Abort(Object stateInfo)
em System.Web.HttpResponse.End()
";
Regex Rx = new Regex(
@"
(?ms) # Multi-line, Dot-All
^ # Beginning of line
(?<data> [^\[\]\r\n]+ ) # (1), Date/time
[ \t]+ # Horizontal whitespace ( could use '\h' instead )
\[ # '['
(?<thread> [0-9]+ ) # (2), Thread number
\] # ']'
[ \t]+ # Horizontal whitespace
(?<nivel> [A-Z]+ ) # (3), Error
[ \t]+ # Horizontal whitespace
(?<classe> # (4 start), Class
(?: [A-Za-z]+ \. )+
[A-Za-z]+
) # (4 end)
[ \t]+ # Horizontal whitespace
- # '-'
[ \t]+ # Horizontal whitespace
(?<message> # (5 start), Message
(?: # Cluster group
(?! # Lookahead
^ # Not the start of a new exception
[^\[\]\r\n]+ # ( basically, not the above code )
[ \t]+
\[
[0-9]+
\]
) # End Lookahead
. # Continue to grab characters
)+ # End Cluster group, do 1 or more times
) # (5 end)
", RegexOptions.IgnorePatternWhitespace);
Match matchX = Rx.Match( sLog );
while ( matchX.Success )
{
Console.WriteLine( "----------------------" );
Console.WriteLine( "New Exception" );
Console.WriteLine( "Date:\t" + matchX.Groups[1] );
Console.WriteLine( "Thread:\t" + matchX.Groups[2] );
Console.WriteLine( "Err:\t" + matchX.Groups[3] );
Console.WriteLine( "Class:\t" + matchX.Groups[4] ) ;
Console.WriteLine( "Msg --" );
Console.WriteLine( matchX.Groups[5] );
matchX = matchX.NextMatch();
}
输出&gt;&gt;
----------------------
New Exception
Date: 2014-02-13 16:06:52,226
Thread: 8
Err: ERROR
Class: solucao.projeto.arquivo
Msg --
AutenticarUsuario
System.Threading.ThreadAbortException: O thread estava sendo anulado.
em System.Threading.Thread.AbortInternal()
em System.Threading.Thread.Abort(Object stateInfo)
em System.Web.HttpResponse.End()
----------------------
New Exception
Date: 2014-02-13 16:06:52,226
Thread: 8
Err: ERROR
Class: solucao.projeto.arquivo
Msg --
AutenticarUsuario
System.Threading.ThreadAbortException: O thread estava sendo anulado.
em System.Threading.Thread.AbortInternal()
em System.Threading.Thread.Abort(Object stateInfo)
em System.Web.HttpResponse.End()
Press any key to continue . . .