<?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"
      autoReload="true"
      internalLogLevel="Trace"
      internalLogFile="c:\temp\log.txt">

    <extensions>
        <!-- load NLog.Extended to enable ASP.NET-specific functionality -->
        <add assembly="NLog.Extended" />
    </extensions>

    <!-- define various log targets -->
    <targets>
        <!-- write logs to file -->
        <target xsi:type="File" name="serviceLogFile" fileName="c:/temp/logs/serviceLog-${shortdate}.log"
            layout="[${longdate}] ${uppercase:${level}} [${machinename}] [${aspnet-request:servervariable=REMOTE_ADDR}] Serving request [${aspnet-request:servervariable=URL}] [${message}]" />

        <target xsi:type="File" name="webLogFile" fileName="c:/temp/logs/webLog-${shortdate}.log"
            layout="[${longdate}] ${message}" />

<!--
        <target xsi:type="File" name="file" fileName="c:/temp/logs/${shortdate}.log"
            layout="${longdate} ${machinename} - ${aspnet-request:servervariable=URL} ${uppercase:${level}} |${logger}|${threadid}|${basedir}|url-monkeybuf: ${message}" />

        <target xsi:type="File" name="file" fileName="c:/temp/logs/${shortdate}.log"
            layout="${longdate} ${aspnet-request:servervariable=URL} ${uppercase:${level}} url-monkeybuf: ${message}" />

        <target xsi:type="File" name="file" fileName="c:/temp/logs/${shortdate}.log"
            layout="${longdate} ${uppercase:${level}} monkeyxbuf: ${message}" />
-->

        <wrapper-target xsi:type="AspNetBufferingWrapper" name="bufferedWebLogFile">
            <wrapper-target xsi:type="PostFilteringWrapper">
                <compound-target xsi:type="SplitGroup">
                    <target-ref name="webLogFile" />
                </compound-target>
                
                <!-- during normal execution only log Info messages -->
                <defaultFilter>level >= LogLevel.Info</defaultFilter>
                
                <!-- if there is at least one error, log everything from trace level -->
                <when exists="level >= LogLevel.Error" filter="level >= LogLevel.Trace" />
            </wrapper-target>
        </wrapper-target>

        <wrapper-target xsi:type="AspNetBufferingWrapper" name="bufferedServiceLogFile">
            <wrapper-target xsi:type="PostFilteringWrapper">
                <compound-target xsi:type="SplitGroup">
                    <target-ref name="serviceLogFile" />
                </compound-target>
                
                <!-- during normal execution only log Info messages -->
                <defaultFilter>level >= LogLevel.Info</defaultFilter>
                
                <!-- if there is at least one error, log everything from trace level -->
                <when exists="level >= LogLevel.Error" filter="level >= LogLevel.Trace" />
            </wrapper-target>
        </wrapper-target>


    </targets>

    <rules>
<!--
        <logger name="*" minlevel="Trace" writeTo="file" />
        <logger name="*" minlevel="Trace" writeTo="allOutputs" />
-->

        <logger name="webLog" minlevel="Trace" writeTo="bufferedWebLogFile" />
        <logger name="serviceLog" minlevel="Trace" writeTo="bufferedServiceLogFile" />
    </rules>
</nlog>
