winform 통합 log4net 프레임 워 크
사용자http://logging.apache.org/log4net/log4net 의 소스 코드 를 다운로드 합 니 다.압축 해제 패키지 후 압축 해제 src 디 렉 터 리 에서 log4net. sln 을 Visual Studio. NET 에 불 러 오고 컴 파일 후 log4net. dll 을 얻 을 수 있 습 니 다.사용 자 는 자신의 프로그램 에 로그 기능 을 추가 하려 면 log 4 net. dll 을 프로젝트 에 도입 하면 됩 니 다.
2 새 Project, 이름: MyLog4net, 프레임 선택. NET Framework 2.0
3 새 클래스 Logger 는 다음 과 같 습 니 다:
using System;
using System.Collections.Generic;
using System.Text;
using log4net;
namespace MyLog4net
{
public class Logger
{
#region
public static ILog init()
{
DateTime now = DateTime.Now;
int year = now.Year;
int month = now.Month;
int date = now.Day;
int hour = now.Hour;
int minute = now.Minute;
int second = now.Second;
int millisecond = now.Millisecond;
string format = year + "/" + month + "/" + date + " " + hour + ":" + minute + ":" + second + ":" + millisecond;
//string pattern = "["+format+"]%n MESSAGE:%message :%-5level%n";
string pattern = "[" + format + "]%n %-5level:[%message]%n%n";
log4net.Layout.PatternLayout pl = new log4net.Layout.PatternLayout(pattern);
log4net.Appender.FileAppender file = new log4net.Appender.FileAppender(pl, "D:/log.txt");
log4net.Config.BasicConfigurator.Configure(file);
return log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
}
public static void Debug(object message, Exception exception)
{
ILog log = init();
log.Debug(message, exception);
}
public static void Debug(object message)
{
ILog log = init();
log.Debug(message);
}
public static void Error(object message, Exception exception)
{
ILog log = init();
log.Error(message, exception);
}
public static void Error(object message)
{
ILog log = init();
log.Error(message);
}
public static void Fatal(object message, Exception exception)
{
ILog log = init();
log.Fatal(message, exception);
}
public static void Fatal(object message)
{
ILog log = init();
log.Fatal(message);
}
public static void Info(object message, Exception exception)
{
ILog log = init();
log.Info(message, exception);
}
public static void Info(object message)
{
ILog log = init();
log.Info(message);
}
public static void Warn(object message, Exception exception)
{
ILog log = init();
log.Warn(message, exception);
}
public static void Warn(object message)
{
ILog log = init();
log.Warn(message);
}
#endregion
}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
WebView2를 Visual Studio 2017 Express에서 사용할 수 있을 때까지Evergreen .Net Framework SDK 4.8 VisualStudio2017에서 NuGet을 사용하기 때문에 패키지 관리 방법을 packages.config 대신 PackageReference를 사용해야...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.