문제

우리가 사용하는 Nlog 으로 우리의 프레임워크 및 로깅할 수 없는 방법을 찾을 보관하는 방식으로 파일 제가 원하는 것입니다.하고 싶은 날짜의 경우 로깅소에서 로그 파일 이름입니다.
전는 모든 로그는 일이 생긴서 2009-10-01 00:00 -> 2009-10-01:23:59 에 배치해야 Log.2009-10-01.log.그러나 모든 로그를 이루어야에 배치 Log.log 를 찌끼다.

현재 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" >
  <extensions>
    <add assembly="My.Awesome.LoggingExentions"/>
  </extensions>
    <targets>
        <target name="file1" xsi:type="File"
              fileName="${basedir}/Logs/Log.log"
              layout="${longdate} ${level:uppercase=true:padding=5} ${session} ${storeid} ${msisdn} - ${logger:shortName=true} - ${message} ${exception:format=tostring}"
              archiveEvery="Day"
              archiveFileName="${basedir}/Logs/Log${shortdate}-{#}.log"
              archiveNumbering="Sequence"
              maxArchiveFiles="99999"
              keepFileOpen="true"
            />
    </targets>
  <rules>
      <logger name="*" minlevel="Trace" writeTo="file1" />
  </rules>
</nlog>

그러나 이 설정은 날짜에 로그파일의 날짜는 새로운 로그파일이 만들어집니다.는 좌절의 원인이기 때문에 나중에 로그를.

그것도 같은 것이 있어야겠다고 생각했어요 적어도 하나#에 archiveFileName,내가 오히려하지 않습니다.그래서 만약 당신이 그것을위한 솔루션을 또한 난 것으로 두 배 감사=)

도움이 되었습니까?

해결책

이런 경우에는 누군가가 여전히 필요한 해결책-요청된 기능이 추가되었습 NLog 최근: https://github.com/NLog/NLog/pull/241, 지만,그것은 여전히 유효하지 않으로 Nuget

다른 팁

아마도 당신을 도울 수 없을 정도로 늦었지만, 당신이해야 할 일은 파일 이름의 날짜를 날짜 레이아웃 렌더러 적절한 날짜 형식. 날짜를 포함시킴으로써 아카이브 기능을 지정할 필요가 없습니다. 날짜가 변경되면 새 파일이 자동으로 생성됩니다.

<?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" >
  <extensions>
    <add assembly="My.Awesome.LoggingExentions"/>
  </extensions>
    <targets>
        <target name="file1" xsi:type="File"
                  fileName="${basedir}/Logs/${date:format=yyyy-MM-dd}.log"
                  layout="${longdate} ${level:uppercase=true:padding=5} ${session} ${storeid} ${msisdn} - ${logger:shortName=true} - ${message} ${exception:format=tostring}"
                  keepFileOpen="true"
                />
    </targets>
  <rules>
      <logger name="*" minlevel="Trace" writeTo="file1" />
  </rules>
</nlog>

어쩌면 이것이 필요한 것일 수도 있습니다. 파일 로그가있는 매일 폴더.

<target xsi:type="File" name="file1" fileName="${basedir}/logs/Log.log"
        layout="${longdate} ${uppercase:${level}} ${message}" />
</targets>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top