2016-12-27 1 views
0

현재 내가 여기 LogException() 방법에서 예외에 대한 명확한 & 상세 정보를 얻을 수 있습니다 follows-예외 로깅

public ActionResult Login() 
{ 
     try 
     { 
      throw new Exception("test"); 
     } 
     catch (Exception ex) 
     { 
      LogException(ex); 
     } 
     return View(); 
    } 

으로 예외를 기록합니다. 나는 소스에 대한 정보를 얻기하지하고 세 abose 경우 OnException 방법 -

public abstract class BaseController : Controller 
{ 
     public BaseController() {} 

     protected override void OnException(ExceptionContext filterContext) 
     { 
      Exception ex = filterContext.Exception; 
      filterContext.ExceptionHandled = true; 

      LogException(ex); 
     } 
} 

과부하 나는 또한 시도

public class MyCustomAttribute : FilterAttribute, IExceptionFilter 
{ 
    public void OnException(ExceptionContext filterContext) 
    { 
     Exception ex = filterContext.Exception;    
     LogException(ex) 
    } 
} 

public class MyCustomAttribute : HandleErrorAttribute 
{ 
    public override void OnException(ExceptionContext filterContext) 
    { 
     Exception ex = filterContext.Exception;    
     LogException(ex) 
    } 
} 

- 나는 동일한 방법을 시도

Created on: 27-Dec-2016, 06.34.33 PM 
Type: System.Exception 
Error Description: test 
Source File: ...\Controllers\LoginController.cs 
Method: Login 
Line: 20 
Column: 17 

below-보기 파일, 방법, 행 및 열 -

Created on: 27-Dec-2016, 06.44.45 PM 
Type: System.Exception 
Error Description: test 
Source File: 
Method: <BeginInvokeAction>b__1e 
Line: 0 
Column: 0 
01 23,516,

이 내 방법은 예외 중 기록하는 것입니다

 public static void Create(Exception exception, String rootDirectoryPath) 
     { 
      try 
      { 
       StackTrace st = new StackTrace(exception, true);     
       StackFrame frame = st.GetFrame(st.FrameCount - 1); 
       string fileName = frame.GetFileName(); 
       string methodName = frame.GetMethod().Name; 
       int line = frame.GetFileLineNumber(); 
       int col = frame.GetFileColumnNumber(); 

       //Other code ..... 
      } 
      catch (Exception) 
      { 
       //do nothing.    
      } 
     } 

내 질문이있다가 그 세 경우와 소스 파일, 방법, 행 및 열 정보를 검색 할 수 있습니까?

매번 try .. catch..을 작성하여 예외를 처리하고 싶지 않습니다.

나는 ELMAH & Log4Net에 관해서 들었습니다. 그러나 라이브러리가 예외로부터 원하는 정보를 제공 할 수 있는지 여부는 확실하지 않습니다.

대단히 죄송합니다.

답변

0

ELMAH으로 휠을 재발 명하고 있습니다. 시도해 봤어? Nuget 패키지와 일부 구성이 완전히 설정되었습니다.

Scot Hanselman 또는 read the tutorial에서 자세한 내용을 읽을 수 있습니다.

+0

글쎄, ELMAH 이외의 방식으로하고 싶다면? –

+0

그런 다음 소스 코드를 확인하여 코드에서 수행하고 복제하는 방법을 확인하는 것이 좋습니다. https://github.com/elmah/Elmah –

0

나는 당신을 위해 추적 예외를 처리하는 OneTrueError의 저자입니다.

솔루션의 문제점은 예외 필터 (및 ASP.NET 프레임 워크 호출로 호출)가 스택 추적의 일부가되어 스택 추적 개체의 프레임이 제대로 작동하지 않는다는 것입니다.

웹 사이트를 제작할 때 .PDB 파일이 포함되어 있지 않으면 파일 번호를 얻지 못할 수도 있습니다.

가장 일반적인 방법은 스택 추적 (PDB 파일이있는 경우)에 줄 번호를 포함하는 exception.ToString()을 기록하는 것입니다.

왜 맞춤 방식을 사용하고 싶습니까?