我正在尝试将异常加载到字段“Exception_type”,以便我可以在我的应用程序上显示它。我有一个正则表达式,但它给了我多个匹配组。我需要的是“Exception_type”字段上的完整消息。如果你能提供帮助,请复制。
正则表达式:
(?<Exception_type>[a-zA-Z]+.*[^,]*[^ ,][^,]*$)
消息:
2016-12-22 14:06:00.4563 System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it 127.0.0.1:30030
at System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult)
at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception)
--- End of inner exception stack trace ---
at System.Net.HttpWebRequest.EndGetRequestStream(IAsyncResult asyncResult, TransportContext& context)
at System.Net.Http.HttpClientHandler.GetRequestStreamCallback(IAsyncResult ar)
--- End of inner exception stack trace ---
at Vinod.MyPos.MyProject.MySubProject.Vendor.Communicator.VendorSaleRequestHandler.<Send>d__13.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Vinod.MyPos.MyProject.MySubProject.Vendor.Communicator.VendorSaleRequestHandler.<Handle>d__12.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Vinod.MyPos.MyProject.MySubProject.Vendor.Communicator.VendorServiceCommunicator.<Send>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Vinod.MyPos.MyProject.MySubProject.Logging.LoggingMySubProjectChildMessageProcessor.<ProcessMessage>d__4.MoveNext() MySubProject ProcessMessage Exception : client token : [c7b9396d-b790-43f5-9561-f01c6dcdddce]
答案 0 :(得分:0)
您可以使用
(?s)^\S+\s+\S+\s+(?<Exception_type>.*$)
请参阅regex demo
^\S+\s+\S+\s+
匹配用1个空格分隔的前2个非空格块文本,其余部分捕获到组1中。
要删除GUID,您需要使用第二步:
\b[a-fA-F0-9]{8}(?:-[a-fA-F0-9]{4}){3}-[a-fA-F0-9]{12}\b
请参阅regex demo,替换为空字符串。
此处,\b
是字边界,[a-fA-F0-9]
与十六进制字符匹配。