<?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\logs\log.txt">

    <variable name="logdir" value="${basedir}\..\..\logs"/>

    <variable name="emailUsername" value="test@bigvi.com" />
    <variable name="emailPassword" value="2aB.qCO5emIz" />

    <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="${logdir}/serviceLog-${machinename}_${date:format=yyyyMMdd}.csv">
            <layout xsi:type="CSVLayout">
                <delimiter>Comma</delimiter>
                <quoting>Auto</quoting>

                <column name="timestamp" layout="${date:format=dd-MM-yyyy HH\:mm\:ss}" />
                <column name="machinename" layout="${machinename}" />
                <column name="message" layout="${message}" />
            </layout>
        </target>

        <target xsi:type="File"
            name="idTheftLogFile"
            fileName="${logdir}/idtheft-${machinename}_${date:format=yyyyMMdd}.csv">
            <layout xsi:type="CSVLayout">
                <delimiter>Comma</delimiter>
                <quoting>Auto</quoting>

                <column name="timestamp" layout="${date:format=dd-MM-yyyy HH\:mm\:ss}" />
                <column name="machinename" layout="${machinename}" />
                <column name="ipaddress" layout="${event-context:item=ipaddress}" />
                <column name="firstname" layout="${event-context:item=firstname}" />
                <column name="lastname" layout="${event-context:item=lastname}" />
                <column name="address" layout="${event-context:item=address}" />
                <column name="city" layout="${event-context:item=city}" />
                <column name="state" layout="${event-context:item=state}" />
                <column name="zip" layout="${event-context:item=zip}" />
                <column name="phonenumber" layout="${event-context:item=phonenumber}" />
                <column name="notes" layout="${message}" />
            </layout>
        </target>

        <target xsi:type="File"
            name="webLogFile"
            fileName="${logdir}/webLog-${machinename}_${date:format=yyyyMMdd}.csv">
            <layout xsi:type="CSVLayout">
              <delimiter>Comma</delimiter>
              <quoting>Auto</quoting>

              <column name="timestamp" layout="${date:format=dd-MM-yyyy HH\:mm\:ss}" />
                <column name="machinename" layout="${machinename}" />
              <column name="accountname" layout="${event-context:item=accountname}" />
              <column name="accountnumber" layout="${event-context:item=accountnumber}" />
                <column name="message" layout="${message}" />
            </layout>
        </target>

        <target xsi:type="Mail"
                name="mail"
                smtpServer="saffron.hmdnsgroup.com"
                smtpPort="587"
                enableSsl="true"
                smtpAuthentication="Basic"
                smtpUserName="${emailUsername}"
                smtpPassword="${emailPassword}"
                from="${emailUsername}"
                to="${emailUsername}"
                subject="Identity Theft Packet Request"
                addNewLines="true"
                />

        <target xsi:type="Mail"
                name="quartzEmail"
                smtpServer="saffron.hmdnsgroup.com"
                smtpPort="587"
                enableSsl="true"
                smtpAuthentication="Basic"
                smtpUserName="${emailUsername}"
                smtpPassword="${emailPassword}"
                from="${emailUsername}"
                to="${emailUsername}"
                subject="Charter Quartz Log"
                addNewLines="true"
                />

        <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>

        <wrapper-target xsi:type="AspNetBufferingWrapper" name="bufferedIdTheftLogFile">
            <wrapper-target xsi:type="PostFilteringWrapper">
                <compound-target xsi:type="SplitGroup">
                    <target-ref name="idTheftLogFile" />
                </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="bufferedIdTheftEmailLogFile">
            <wrapper-target xsi:type="PostFilteringWrapper">
                <compound-target xsi:type="SplitGroup">
                    <target-ref name="mail" />
                </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="webLog" minlevel="Trace" writeTo="bufferedWebLogFile" />
        <logger name="serviceLog" minlevel="Trace" writeTo="bufferedServiceLogFile" />
        <logger name="idTheftLog" minlevel="Trace" writeTo="bufferedIdTheftLogFile" />
        <logger name="idTheftEmailLog" minlevel="Trace" writeTo="bufferedIdTheftEmailLogFile" />

        <logger name="quartzEmailLog" minlevel="Trace" writeTo="quartzEmail" />
    </rules>
</nlog>
