How do you configure nlog to change the file target path based on the computers architecture (32/64 bit).

701 Views Asked by At

Example on 32 bit OS the file target path would be c:\temp\32\ and on a 64bit c:\temp\64

1

There are 1 best solutions below

5
On

You can use a layout renderer in the filenname.

You can use:

  • The Environment layout renderer with PROCESSOR_ARCHITECTURE variable which is AMD64 or X86 (or IA64, see superuser):

    Usage: ${environment:PROCESSOR_ARCHITECTURE}

    Example:

    <target 
       xsi:type="File"
       name="file1" 
       fileName="c:\temp\${when:when='${environment:PROCESSOR_ARCHITECTURE}'='X86':inner=32:else=64}\file.log" /> 
    
  • Or, use the When layout renderer for you conditions.

    Example, two targets:

    <target 
       xsi:type="File"
       name="file_32" 
       fileName="c:\temp\32\file.log" /> 
    <target 
       xsi:type="File"
       name="file_64" 
       fileName="c:\temp\64\file.log" /> 
    

    and two rules:

    <rules>
        <logger name="*" writeTo="file_32">
            <filters>
                <when condition="'${environment:PROCESSOR_ARCHITECTURE}'!='X86'" action="Ignore" />
            </filters>
        </logger>
        <logger name="*" writeTo="file_64">
            <filters>
                <when condition="'${environment:PROCESSOR_ARCHITECTURE}'='X86'" action="Ignore" />
            </filters>
        </logger>
    </rules>