이 질문은 우스꽝 스럽지만 대답을 찾을 수 없다는 것을 알고 있습니다. 포스트 샤프는 System.Diagnostics에 의해 콘솔에 로그를 기록하지만 별도의 파일에 로그를 기록해야합니다. 그렇게 할 방법이 있습니까?포스트 스케이프에서 콘솔 대신 파일에 로그 쓰기
미리 감사
이 질문은 우스꽝 스럽지만 대답을 찾을 수 없다는 것을 알고 있습니다. 포스트 샤프는 System.Diagnostics에 의해 콘솔에 로그를 기록하지만 별도의 파일에 로그를 기록해야합니다. 그렇게 할 방법이 있습니까?포스트 스케이프에서 콘솔 대신 파일에 로그 쓰기
미리 감사
에 당신은 당신의 자신의 리스너를 등록 할 System.Diagnostics.Trace.Listeners 속성을 사용해야합니다. 당신은 응용 프로그램의 진입 점에서이 같은 코드가 필요합니다 :
가 나는 또한 발견using (StreamWriter sw = new StreamWriter("file.txt"))
using (TextWriterTraceListener tl = new TextWriterTraceListener(sw))
{
Trace.Listeners.Add(tl);
try
{
// execute your program here
}
finally
{
Trace.Listeners.Remove(tl);
}
}
나는의 app.config에서이 작업을 수행 할 수 있습니다 다음과 같은 :
<system.diagnostics>
<trace autoflush="true" indentsize="4">
<listeners>
<add name="myListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="C:\\log.txt" />
<remove name="Default" />
</listeners>
</trace>
</system.diagnostics>