<?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="Info"
      internalLogFile="c:\temp\internal-nlog.txt"
      
      >

	<!-- enable asp.net core layout renderers -->
	<extensions>
		<add assembly="NLog.Web.AspNetCore"/>
  </extensions>

	<!-- the targets to write to -->
	<targets>
    <target xsi:type="Database"
         name="Database"
         dbProvider="Microsoft.Data.SqlClient.SqlConnection, Microsoft.Data.SqlClient"
         connectionString=""
         keepConnection="True"
         isolationLevel="ReadCommitted"
         commandType="Text"
         installConnectionString="Layout">
      <commandText>
        INSERT INTO [dbo].[tPW_Log] ([Date],[Area],[Action],[Severity],[Status],[Username],[DomainName],[Request],[Message],[CallSite]) VALUES
        (GetDate(), @Area, @Action, @Severity, @Status, @Username, @DomainName, @Request, @Message, @CallSite)
      </commandText>
      <parameter name="@Area" layout="${event-properties:logmodel:objectpath=Area}" />
      <parameter name="@Action" layout="${event-properties:logmodel:objectpath=Action:truncate=100}" />
      <parameter name="@Severity" layout="${event-properties:logmodel:objectpath=Severity}" />
      <parameter name="@Status" layout="${event-properties:logmodel:objectpath=Status}" />
      <parameter name="@Username" layout="${event-properties:logmodel:objectpath=UserName:truncate=100}" />
      <parameter name="@DomainName" layout="${event-properties:logmodel:objectpath=Domain:truncate=50}" />
      <parameter name="@Request" layout="${event-properties:logmodel:objectpath=Request:truncate=2000}" />
      <parameter name="@Message" layout="${event-properties:logmodel:objectpath=Message:truncate=250}" />
      <parameter name="@CallSite" layout="${callsite:truncate=240} ${callsite-linenumber}" />
      
    </target>

    <target xsi:type="Database"
         name="SQLTrace"
         dbProvider="Microsoft.Data.SqlClient.SqlConnection, Microsoft.Data.SqlClient"
         connectionString=""
         keepConnection="True"
         isolationLevel="ReadCommitted"
         commandType="Text"
         installConnectionString="Layout">
      <commandText>
        INSERT INTO TPA_SYSLOGEVENTS (ACAPPL, ANUSERID, ADTIME, ACHOSTNAME, ACDATABASENAME, ACVALUE, ADDURATION, ACGUID ) VALUES
        ('PW', 1, GETDATE(), 'PANTHEON WEB', @Database, @AcValue, @Duration, @Guid)
      </commandText>
      <parameter name="@AcValue" layout="${event-properties:logmodel:objectpath=AcValue}" />
      <parameter name="@Database" layout="${event-properties:logmodel:objectpath=Database:truncate=30}" />
      <parameter name="@Duration" layout="${event-properties:logmodel:objectpath=Duration}" />
      <parameter name="@Guid" layout="${event-properties:logmodel:objectpath=Guid}" />
    </target>
    
    <!-- write logs to file  -->
		<target xsi:type="File" name="allfile" fileName="c:\temp\nlog-all-${shortdate}.log"
				layout="${longdate}|${event-properties:item=EventId_Id}|${uppercase:${level}}|${logger}|${message} ${exception:format=tostring}" />

		<!-- another file log, only own logs. Uses some ASP.NET core renderers --><!--
		<target xsi:type="File" name="ownFile-web" fileName="c:\temp\nlog-own-${shortdate}.log"
				layout="${longdate}|${event-properties:item=EventId_Id}|${uppercase:${level}}|${logger}|${message}|distart ${all-event-properties} diend ${event-properties:p2:objectpath=Action} ${exception:format=tostring}|url: ${aspnet-request-url}|action: ${aspnet-mvc-action}" />-->
	</targets>

	<!-- rules to map from logger name to target -->
	<rules>
    <logger name="PantheonRA.*" minlevel="Trace" writeTo="Database" />
    <logger name="PantheonRA.WebApi.DbTraceInterceptor" minlevel="Trace" writeTo="SQLTrace" />
    <!--<logger name="Microsoft.EntityFrameworkCore.Database.Command" minlevel="Trace" writeTo="allfile" />-->
    <!--All logs, including from Microsoft-->
		<!--<logger name="*" minlevel="Trace" writeTo="allfile" />

		--><!--Skip non-critical Microsoft logs and so log only own logs--><!--
		<logger name="Microsoft.*" maxlevel="Info" final="true" />
		--><!-- BlackHole without writeTo 
		<logger name="PantheonRA.*" minlevel="Trace" writeTo="ownFile-web" />-->
	</rules>
</nlog>