웹 사이트 예외를 응용 프로그램 이벤트 로그에 쓰려고 시도하고 여러 가지 방법으로 시도했지만 너무 많은 게시물을 보았지만 여전히 그렇게 할 수 없습니다. 누구든지이 일을 도와 주길 바랍니다. 여기에 내 코드응용 프로그램 이벤트 로그에 쓰기
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());
}
}
'EventLog.CreateEventSource (logName, logName);'관리 권한이 필요합니다 ... 하지만 올바른 경로에 우리를 올리려면 – TGlatzer
BTW를 얻을 수 있습니다. NLog는 EventLog를 Target으로 지원한다고 생각합니다. – TGlatzer
나는 모든 권한을 가지고 있으며 관리자로만 느껴지지만 여전히 같은 오류가 발생합니다. – 62071072SP