메소드 콜에서 UI를 조작하면 다중 스레드에서 에러 발생합니다. 주의해주세요. 

Control.Invoke 에서 행업 걸립니다...

BeginInvoke에서는 괜찮지만, EndInvoke 에서 행업걸립니다...

다중 스레드에서 컨트롤러 표기에 관한 부분은 메소드 콜에서 자제해주세요.



MainPage 클레스에 정적 LogMethod 메소드를 만들어 주세요. 

Rule에 의해 움직이기 때문에, 해당 클레스 뿐 아니라 다른 곳에서 찎은 로그도 이곳에 로그가 발생합니다.


// NLog 이벤트 등록 메소드

private void Register_NLog_MethodCall()

{

MethodCallTarget target = new MethodCallTarget();

target.ClassName = typeof(MainPage).AssemblyQualifiedName;

target.MethodName = "LogMethod";

target.Parameters.Add(new MethodCallParameter("${level}"));

target.Parameters.Add(new MethodCallParameter("${message}"));


var wrapper = new AsyncTargetWrapper(target, 5000, AsyncTargetWrapperOverflowAction.Discard);

var rule = new LoggingRule("*", LogLevel.Trace, target);


NLog.LogManager.Configuration.AddTarget("method", wrapper);

NLog.LogManager.Configuration.LoggingRules.Add(rule);

NLog.LogManager.ReconfigExistingLoggers();


// 리스트 박스 등록

_lbx = lbx_log;

}

'Knowledge > NLog' 카테고리의 다른 글

NLog 설정 Programmically 등록 (수동)  (0) 2018.04.26

+ Recent posts