2013-01-22 3 views
0

enter image description here 웹 사이트 예외를 응용 프로그램 이벤트 로그에 쓰려고 시도하고 여러 가지 방법으로 시도했지만 너무 많은 게시물을 보았지만 여전히 그렇게 할 수 없습니다. 누구든지이 일을 도와 주길 바랍니다. 여기에 내 코드응용 프로그램 이벤트 로그에 쓰기

public class CustomHandleErrorAttribute : ActionFilterAttribute 

{ 
    public override void OnActionExecuted(ActionExecutedContext filterContext) 
    { 
     { 
      // Bail if we can't do anything; app will crash. 
      if (filterContext == null) 
       return; 
      // since we're handling this, log to ELMAH(Error logging modules and handler) 

      var ex = filterContext.Exception ?? new Exception("No further information exists."); 
      WriteToEventLog(ex); 

      filterContext.ExceptionHandled = true; 
      var data = new ErrorPresentation 
      { 
       ErrorMessage = HttpUtility.HtmlEncode(ex.Message), 
       TheException = ex, 
       ShowMessage = filterContext.Exception != null, 
       ShowLink = false 
      }; 

      filterContext.Result = new ViewResult 
             { 
              ViewName = "~/Views/Home/ErrorPage.aspx" 
             }; 
     } 
    } 

    public void WriteToEventLog(Exception exception) 
    { 
     // todo : now I need to write this exception to Event log 

     String cs = "FailureAudit"; 
     var thisMachineName = "abc"; 
     var logName = "Application"; 

     EventLog eventLog = new EventLog(logName, thisMachineName); 
     if (!EventLog.SourceExists(logName)) 
     { 
      EventLog.CreateEventSource(logName, logName); 

     } 
     eventLog.Source = cs; 
     eventLog.EnableRaisingEvents = true; 
     //eventLog.WriteEntry(exception.ToString(), EventLogEntryType.Error); 
     eventLog.WriteEntry(exception.ToString()); 

    } 
} 
+2

'EventLog.CreateEventSource (logName, logName);'관리 권한이 필요합니다 ... 하지만 올바른 경로에 우리를 올리려면 – TGlatzer

+0

BTW를 얻을 수 있습니다. NLog는 EventLog를 Target으로 지원한다고 생각합니다. – TGlatzer

+0

나는 모든 권한을 가지고 있으며 관리자로만 느껴지지만 여전히 같은 오류가 발생합니다. – 62071072SP

답변

1

내 컴퓨터에 (관리자 권한) 아래 cmd를 실행하고 지금은 응용 프로그램 이벤트 로그에 대한 제안과 의견에 대한

eventcreate /ID 1 /L APPLICATION /T INFORMATION /SO MYSOURCE /D "MY-SOURCE" 

감사를 작성할 수 있습니다.

+0

이 명령은 로그를 작성하고 첫 번째 정보 행을 삽입합니다. 그 후에는 더 이상 필요하지 않습니다. 설치 패키지를 공개하는 사람들은 스크립트에 비슷한 내용을 넣어야합니다. – ManuelJE

관련 문제