log4net을 주로 사용하고 있지만, 이번에 Scott의 blog에서 소개한 ELMAH를 보고 감탄~
db를 이용한 log 기록 및 web page를 통해 log monitor, e-mail notification 까지 모두 가능하다.
가장 보고 놀라버린 log monitor
MSSQL, MySql, SQLite, Oracle 을 모두 지원하며 각각에 대한 Filtering까지 모두 지원한다.
에서 간단한 소개가 있고, web.config 설정은 다음과 같다.
1. configsections에 elmah 등록
<sectionGroup name="elmah">
<section name="security" requirePermission="false" type="Elmah.SecuritySectionHandler, Elmah"/>
<section name="errorLog" requirePermission="false" type="Elmah.ErrorLogSectionHandler, Elmah"/>
<section name="errorMail" requirePermission="false" type="Elmah.ErrorMailSectionHandler, Elmah"/>
</sectionGroup>
2. configuration에 elmah 세부 정보 등록
<elmah>
<errorLog type="Elmah.SQLiteErrorLog, Elmah" connectionStringName="ELMAH.SQLite" />
<errorMail from="fromaddress" to="toaddress" smtpServer="smtpmails" subject="Error Mails" />
</elmah>
3. httpmodule에 사용할 monitor page 이름과 errorMail 모듈 등록
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah"/>
<add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah"/>
4. httphandlers에 사용될 monitor page 등록
<add verb="POST,GET,HEAD" path="traceError.axd" type="Elmah.ErrorLogPageFactory, Elmah" />
5. customerError mode를 on으로 변경
<customErrors mode="On" defaultRedirect="/Home/Index">
다른 페이지에도 한번 적용해보고 싶은 내용. ^^
그리고 ASP .NET MVC 모델에 적용하기 위해서 가장 쉬운 방법은 ErrorHandlerAttribute를 상속받은 ELMAH 전용 ErrorHandler를 만들어주면 사용이 매우 편하다.