없이 붙 잡았다 : 몇 분 동안문제는이 이벤트, 이벤트 래퍼와 핸들러와 이상한 문제가 발생 인수
public delegate void StatusUpdateHandler(string message, Exception exc, SeverityLevel severity);
public event StatusUpdateHandler StatusUpdate;
private void FireStatusUpdate(string message)
{
if (this.StatusUpdate != null)
this.StatusUpdate(message, null, SeverityLevel.None);
}
void scanDocProcessor_StatusUpdate(string message, Exception exc, SeverityLevel severity)
{
try
{
if (exc != null)
{
if (severity >= setSevLevel)
this._logger.Log(message + Environment.NewLine + exc.ToString(), LogEntryType.Emergency, "OCR Submission Processor Status Update", true);
else
this._logger.Log(message + Environment.NewLine + exc.ToString(), LogEntryType.Error, "OCR Submission Processor Status Update", false);
}
else if (severity >= setSevLevel)
{
this._logger.Log(message, LogEntryType.Info, "OCR Submission Processor Status Update", true, true);
}
else
this._logger.Log(message, LogEntryType.Info, "OCR Submission Processor Status Update", false);
}
catch (Exception)
{
EventLog.WriteEntry("Russia OCR Submission Processor", "Could not log status update event: " + exc.ToString(), EventLogEntryType.Information);
}
}
의 _logger 메시지 로깅을 중지하고 대신 나는 이러한 메시지를받은 이벤트 로그 :
상태 업데이트 이벤트를 기록 할 수 없습니다 : System.NullReferenceException : 개체 참조가 개체의 인스턴스로 설정되지 않았습니다. ScannedService.Processor.ProcessQueue에서 ScannedService.Processor.FireStatusUpdate (문자열 메시지) 에서 ScannedService.scanDocProcessor_StatusUpdate (문자열 메시지, 예외 EXC, SeverityLevel 심각도) 에서 (개체 개체)
내가 어떻게 이벤트 혼란 스러워요 exc.ToString()을 작성해야 할 때 로그에서 스택 추적을 얻을 수 있습니다. scanDocProcessor_StatusUpdate 메서드에 대한 일리노이 (IL)를 살펴보면 Exception 객체가 초기화되지 않습니다. 그 외에도 nullreferenceexception이 던져지는 방법을 모른다. Log 메소드가 예외를 잡을 때, 그것을 버리거나 "throw;"로 다시 throw합니다. message 매개 변수는 null이 아니며 SeverityLevel은 열거 형입니다.
'Exception'를 잡을하지 마십시오. –