nlog 튜토리얼
nlog 시작하기
수색…
비고
NLog는 .NET 용 무료 로깅 라이브러리입니다. 이것은 BSD-3에 따라 라이센스가 부여되어 상업적 용도로 사용될 수 있음을 의미합니다.
NLog의 소스는 GitHub 에서 찾을 수 있습니다.
버전
주요 버전 :
번역 | 릴리즈 노트 | 출시일 |
---|---|---|
4 | 릴리즈 노트 | 2015-06-09 |
삼 | 릴리즈 노트 | 2014-06-02 |
2 | 릴리즈 노트 | 2011 년 7 월 18 일 |
1 | 릴리즈 노트 | 2011-01-07 |
첫 번째 로그 작성
NLog.Config 패키지를 설치하십시오. (NuGet 3 사용자는 NLog 를 설치하고 수동으로 설정을 추가해야합니다.) 로거에 작성 :
using NLog;
public class MyClass
{
private static Logger logger = LogManager.GetCurrentClassLogger();
public void MyMethod1()
{
logger.Trace("Sample trace message");
logger.Debug("Sample debug message");
logger.Info("Sample informational message");
logger.Warn("Sample warning message");
logger.Error("Sample error message");
logger.Fatal("Sample fatal error message");
// alternatively you can call the Log() method
// and pass log level as the parameter.
logger.Log(LogLevel.Info, "Sample informational message");
try
{
SendMail();
}
catch(Exception ex)
{
//example writing exception
logger.Error(ex, "Error when sending mail");
}
}
}
이 예제 구성은 NLog.Config 패키지와 함께 추가해야합니다. 그렇지 않으면 응용 프로그램의 루트에 다음을 추가하거나 .dll 옆에 "nlog.config"
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd"
autoReload="true"
throwExceptions="false"
internalLogLevel="Off" internalLogFile="c:\temp\nlog-internal.log">
<!-- optional, add some variables
https://github.com/nlog/NLog/wiki/Configuration-file#variables
-->
<variable name="myvar" value="myvalue"/>
<!--
See https://github.com/nlog/nlog/wiki/Configuration-file
for information on customizing logging rules and outputs.
-->
<targets>
<!--
add your targets here
See https://github.com/nlog/NLog/wiki/Targets for possible targets.
See https://github.com/nlog/NLog/wiki/Layout-Renderers for the possible layout renderers.
-->
<!-- Write events to a file with the date in the filename. -->
<target xsi:type="File" name="f" fileName="${basedir}/logs/${shortdate}.log"
layout="${longdate} ${uppercase:${level}} ${message} ${exception}" />
</targets>
<rules>
<!-- add your logging rules here -->
<!--
Write all events with minimal level of Debug (So Debug, Info, Warn, Error and Fatal, but not Trace) to "f" -->
<logger name="*" minlevel="Debug" writeTo="f" />
</rules>
</nlog>
config는 로그 메시지를 파일에 기록합니다.
Modified text is an extract of the original Stack Overflow Documentation
아래 라이선스 CC BY-SA 3.0
와 제휴하지 않음 Stack Overflow