<?xml version="1.0" encoding="utf-8"?>

<nlog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      throwConfigExceptions="true">
    <targets>
        <target xsi:type="File"
                name="ErrorToSingleFile"
                fileName="${specialfolder:folder=ApplicationData}/iiko/CashServer/Logs/POS/Plugin/Error.log"
                layout="${longdate} | ${pad:padding=-2:inner=${threadid}} | ${logger:shortName=true} | ${message}${newline}${exception:format=toString,Data}${newline}"
                archiveFileName="${specialfolder:folder=ApplicationData}/iiko/CashServer/Logs/POS/Archive/Plugin/Error-{#}.zip"
                archiveEvery="Day"
                archiveNumbering="Date"
                archiveDateFormat="yyyy-MM-dd"
                maxArchiveFiles="30"
                enableArchiveFileCompression="true" />
        <target xsi:type="File"
                name="AllEventsToSingleFile"
                fileName="${specialfolder:folder=ApplicationData}/iiko/CashServer/Logs/POS/Plugin/AllEvents.log"
                layout="${longdate} | ${pad:padding=-2:inner=${threadid}} | ${pad:padding=-5:inner=${level:uppercase=true}} | ${pad:padding=-20:fixedLength=True:inner=${logger:shortName=true}} | ${message}${onexception: [${exception:format=Message}]}"
                archiveFileName="${specialfolder:folder=ApplicationData}/iiko/CashServer/Logs/POS/Archive/Plugin/AllEvents-{#}.zip"
                archiveEvery="Day"
                archiveNumbering="Date"
                archiveDateFormat="yyyy-MM-dd"
                maxArchiveFiles="30"
                enableArchiveFileCompression="true" />
        <target xsi:type="File"
                name="SingleToFile"
                fileName="${specialfolder:folder=ApplicationData}/iiko/CashServer/Logs/POS/Plugin/${logger:shortName=true}.log"
                layout="${longdate} | ${pad:padding=-2:inner=${threadid}} | ${pad:padding=-5:inner=${level:uppercase=true}} | ${message}${onexception: [${exception:format=Message}]}"
                archiveFileName="${specialfolder:folder=ApplicationData}/iiko/CashServer/Logs/POS/Archive/Plugin/${logger:shortName=true}-{#}.zip"
                archiveEvery="Day"
                archiveNumbering="Date"
                archiveDateFormat="yyyy-MM-dd"
                maxArchiveFiles="30"
                enableArchiveFileCompression="true" />
        <target xsi:type="File"
                name="SingleToConcurrentFile"
                concurrentWrites="false"
                keepFileOpen="false"
                fileName="${specialfolder:folder=ApplicationData}/iiko/CashServer/Logs/POS/Plugin/${logger:shortName=true}.log"
                layout="${longdate} | ${pad:padding=-2:inner=${threadid}} | ${pad:padding=-5:inner=${level:uppercase=true}} | ${message}"
                archiveFileName="${specialfolder:folder=ApplicationData}/iiko/CashServer/Logs/POS/Archive/Plugin/${logger:shortName=true}-{#}.zip"
                archiveEvery="Day"
                archiveNumbering="Date"
                archiveDateFormat="yyyy-MM-dd"
                maxArchiveFiles="30"
                enableArchiveFileCompression="true" />
        <!-- Структурированное логирование в JSON-формате -->
        <target xsi:type="File"
                name="SingleToJson"
                fileName="${specialfolder:folder=ApplicationData}/iiko/CashServer/Logs/POS/Plugin/${logger:shortName=true}.json"
                archiveFileName="${specialfolder:folder=ApplicationData}/iiko/CashServer/Logs/POS/Archive/Plugin/${logger:shortName=true}-{#}.zip"
                archiveEvery="Day"
                archiveNumbering="Date"
                archiveDateFormat="yyyy-MM-dd"
                maxArchiveFiles="30">
            <layout xsi:type="JsonLayout">
                <attribute name="time" layout="${longdate}" />
                <attribute name="level" layout="${level:upperCase=true}" />
                <attribute name="message" layout="${message}" />
                <attribute name="properties" encode="false">
                    <layout xsi:type="JsonLayout" includeGdc="true" includeAllProperties="true" />
                </attribute>
            </layout>
        </target>
    </targets>
    <rules>
        <logger name="VitMonitoringLogger" minlevel="Info" writeTo="SingleToJson" final="true" />
        <logger name="*" minlevel="Info" writeTo="AllEventsToSingleFile" />
        <logger name="*" minlevel="Error" writeTo="ErrorToSingleFile" />
        <logger name="*.ApplicationRoot" minlevel="Trace" writeTo="SingleToFile" />
        <logger name="*.BusinessLogicControllerComponent" minlevel="Trace" writeTo="SingleToFile" />
        <logger name="*.ViewComponent" minlevel="Trace" writeTo="SingleToFile" />
        <logger name="*.ModelComponent" minlevel="Trace" writeTo="SingleToFile" />
        <logger name="*.ModelNotifierComponent" minlevel="Trace" writeTo="SingleToFile" />
        <logger name="*.NotifierComponent" minlevel="Trace" writeTo="SingleToFile" />
        <logger name="CommandProcessorComponent" minlevel="Trace" writeTo="SingleToFile" />
        <logger name="*.ViewActionBufferComponent" minlevel="Trace" writeTo="SingleToFile" />
        <logger name="*.MediatorComponent" minlevel="Trace" writeTo="SingleToFile" />
        <logger name="*.PerformanceActionLoggerWrapper" minlevel="Trace" writeTo="SingleToConcurrentFile" />
        <logger name="ComboSpecificationClient" minlevel="Trace" writeTo="SingleToFile" />
        <logger name="QueueProcessor" minlevel="Trace" writeTo="SingleToFile" />
        <logger name="*.ForceCloseOrderHandler" minlevel="Trace" writeTo="SingleToJson" />
    </rules>
</nlog>