1. log4net 사용방법.
프로그램 다운로드
http://logging.apache.org/log4net/downloads.html 에서 다운로드
2. 압축을 풀고, bin\net\1.1\release 디렉토리에서 log4net.dll 파일을
프로젝트 bin 폴더에 복사한다.
3. Web.config 파일에 log4net Section 등록.
-----------------------------------------------------------------------------------------------------------------------------------------------
<configSections>
<!-- Log4net Section -->
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
</configSections>
-----------------------------------------------------------------------------------------------------------------------------------------------
configSections 가 존재할 경우 <section /> 부분만 기존 섹션에 추가한다.
아래는 elmah 로깅 서비스와 같이 존재할 경우임.
-----------------------------------------------------------------------------------------------------------------------------------------------
<configSections>
<!-- Allows for a new section group to the Web.config -->
<sectionGroup name="gotdotnet.elmah">
<!-- Indicates that inside the section group there will be an errorLog section -->
<section
name="errorLog"
type="System.Configuration.SingleTagSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<!-- Indicates that inside the section group there will be an errorMail section -->
<section
name="errorMail"
type="System.Configuration.SingleTagSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</sectionGroup>
<!-- Log4net Section -->
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
</configSections>
-----------------------------------------------------------------------------------------------------------------------------------------------
4. log4net 섹션 세부 설정.
-----------------------------------------------------------------------------------------------------------------------------------------------
<log4net>
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender,log4net">
<param name="File" value="d:\\WebDevel\\CloseBetaLog\CloseBeta.log" />
<param name="AppendToFile" value="true" />
<param name="DatePattern" value="-yyyy-MM-dd" />
<param name="RollingStyle" value="Date" />
<param name="StaticLogFileName" value="true" />
<layout type="log4net.Layout.PatternLayout,log4net">
<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n" />
</layout>
</appender>
<!-- root 카테고리를 설정하고 appender들을 추가한다. 기본우선순위 (default priority) 역시 설정된다. -->
<root>
<priority value="WARN" />
<appender-ref ref="RollingLogFileAppender" />
</root>
</log4net>
-----------------------------------------------------------------------------------------------------------------------------------------------
5. Global.asax 의 Application_Start 메서드에서 log4net 을 초기화 시킨다.
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
// log4net Configure
log4net.Config.DOMConfigurator.Configure();
}
6. 사용방법.
클래스를 하나 생성.
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using log4net;
public partial class LoggingTest : System.Web.UI.Page
{
private static ILog logger = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
protected void Page_Load(object sender, EventArgs e)
{
LoggingTest.logger.Error(System.DateTime.Now + " : ???④릿 濡?洹??????);
}
}
7. 로그 확인.
d:\WebDevel\CloseBetaLog\CloseBeta.log 를 열어보면 아래와 같이 남는다.
2006-03-27 14:15:26,053 [3536] ERROR LoggingTest [(null)] - 2006-03-27 오후 2:15:26 : 에 남긴 로그입니다
2006-03-27 14:15:26,084 [3536] ERROR LoggingTest [(null)] - 2006-03-27 오후 2:15:26 : 에 남긴 로그입니다
2006-03-27 14:15:26,115 [3536] ERROR LoggingTest [(null)] - 2006-03-27 오후 2:15:26 : 에 남긴 로그입니다
2006-03-27 14:15:26,147 [3536] ERROR LoggingTest [(null)] - 2006-03-27 오후 2:15:26 : 에 남긴 로그입니다
2006-03-27 14:15:26,178 [3536] ERROR LoggingTest [(null)] - 2006-03-27 오후 2:15:26 : 에 남긴 로그입니다
2006-03-27 14:15:26,209 [3536] ERROR LoggingTest [(null)] - 2006-03-27 오후 2:15:26 : 에 남긴 로그입니다
2006-03-27 14:18:48,584 [2400] ERROR LoggingTest [(null)] - 2006-03-27 오후 2:18:48 : 에 남긴 로그입니다
8. 윈도우 Tail 유틸리티로 로그 꼬리만 계속 보기.
http://ophilipp.free.fr/op_tail.htm 에서 다운로드 후 로그 파일을 지정한 후 start 하면 됨.
'.NET > ASP.NET' 카테고리의 다른 글
닷넷 펫스토어 4 (0) | 2006.04.11 |
---|---|
[asp.net]서버 응용 프로그램을 사용할 수 없습니다. (1) | 2006.03.28 |
[펌]ASP.NET에서 자바 스크립트를 외부에서 불러서 사용할때 에러가 .. (0) | 2006.03.21 |
[펌]ASP.NET Whidbey의 향상된 캐싱 기능 (0) | 2006.03.06 |
[펌] ASP.NET 기본 제공 기능을 활용하여 웹 공격 차단 (0) | 2006.02.09 |