आप एक अपवाद वस्तु से एक StackTrace
वस्तु बना सकते हैं। इसमें StackFrame
एस शामिल होगा जिसमें अपवाद की जानकारी है। तब आप फ़ाइल और विधि के नाम, पदों और क्या उपलब्ध नहीं हो सकते हैं। बेशक यह बिना कहने के जाना चाहिए, लेकिन यह सब केवल उपलब्ध है, आपने डीबगिंग प्रतीकों को शामिल करने के लिए अपनी असेंबली संकलित की है (जो मुझे लगता है कि एमवीसी में उपलब्ध हो सकता है)।
catch (Exception ex)
{
var st = new StackTrace(ex, true); // create the stack trace
var query = st.GetFrames() // get the frames
.Select(frame => new
{ // get the info
FileName = frame.GetFileName(),
LineNumber = frame.GetFileLineNumber(),
ColumnNumber = frame.GetFileColumnNumber(),
Method = frame.GetMethod(),
Class = frame.GetMethod().DeclaringType,
});
// log the information obtained from the query
}
स्रोत
2011-03-24 11:33:26
अच्छा काम दोस्त! –