2012-05-15 3 views
0

aspnetdb_log 파일의 이벤트 로그에 기록하는 방법에 대해 알고있는 사람은 원래 코드 줄이지만 Log.LogException (..)이있는 웹에서 찾은 코드 스 니핏입니다. 작동하지 않거나 사용할 라이브러리를 모른다. 따라서 EventLog를 사용했다. 내가 뭘하고 싶은지 오류 또는 이벤트 aspnetdb_log 파일에 누군가가 어떤 수정을 다음 회신 감사를 남겨주세요 제발 초기 단계에 있기 때문에 그것을 테스트하지 않은 내 코드 작동합니다. 이WriteToEventLog sql aspnet_db 로그 파일에 예외 로깅

private void WriteToEventLog(Exception e, string action) 
{ 
    string message = action + "-" + e.Message; 

    if (!EventLog.SourceExists("aspnetdb_log")) 
    { 
     EventLog.CreateEventSource("aspnetdb_log", "aspnetdb_log"); 
    } 

    EventLog log = new EventLog(); 
    log.Source = "aspnetdb_log"; 
    log.WriteEntry(message, EventLogEntryType.Error); 

    // original code doesn't work 
    // Log.LogException(message, e, LogCategory.Membership, TraceEventType.Error); 
} 
+0

왜이로 추적 할 않는 다른 펜더를 사용하는 방법에 대한 아주 좋은 튜토리얼은 DB입니까? – abatishchev

답변

0

내가 찾거나 원하는 데이터베이스에 작성하는 사용자 정의 TraceListener를 작성하는 것이 좋습니다 사용자 지정 멤버 자격 공급자입니다.

그런 다음 클래스에서 TraceSource을 사용하고 Web.config에서 둘 다 구성하십시오.

등급 :

public class SqlTraceListener : TraceListener 
{ 
    ... 
} 

사용법 :

private static TraceSource _traceSource = new TraceSource("MySource"); 

_traceSource.Trace(...); 

구성 :

당신은 CreateEventSource를 사용하여 EventSource를 만들 수있는 관리자 권한이 필요
<system.diagnostics> 
    <sources> 
     <source name="MySource" /> 
    </sources> 
    <sharedListeners> 
     <add name="sql" type="SqlTraceListener" /> 
    </sharedListeners> 
    <trace autoflush="true"> 
    </trace> 
</system.diagnostics> 
+0

내 코드가 작동합니까 – ONYX

+0

@KDM : EventLog 클래스는 데이터베이스에 데이터를 쓰지 않습니다. TraceSource + TraceListener가됩니다. – abatishchev

+0

top aspnetdb_log 파일을 쓸 수 있습니까? 아니면 텍스트 파일에만 쓸 수 있습니까? – ONYX

0

.

aspnetdb_log 소스가 이미있는 경우 코드가 올바르게 실행되어야합니다.

+0

db_log는 데이터베이스이며 이벤트 로그는 그대로입니다. 나머지는 네가 맞아. – abatishchev

0

Log4Net에는 데이터베이스, 이벤트 로그 및 텍스트 파일과 같은 다른 위치에 로그 할 수있는 여러 가지 appenders가 있습니다.

Here