multiple database tables

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

multiple database tables

maxh
Hello, I've searched all over and can't find an answer. Is it possible to define and use multiple database tables and each table to have it's own schema? I've tried to set it up and so far I can only log to one table and second table never gets written to. I've enabled nlog internal debugging and looks like nlog gets confused and applies the same target sql command to both targets.


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

	<variable name="logDirectory" value="${basedir}/logs/"/>
	<targets async="true">
		<target name="file" xsi:type="AsyncWrapper" queueLimit="1000" overflowAction="Discard">
			<target xsi:type="File"
			  layout="${longdate} ${message}"
			  fileName="${logDirectory}${level}.nlog"
			  archiveFileName="${logDirectory}archives/log.${level}.{####}.nlog"
			  archiveEvery="Day"
			  archiveNumbering="Rolling"
			  concurrentWrites="true"
			  keepFileOpen="true"/>
		</target>

		<target name="Order" xsi:type="AsyncWrapper" queueLimit="500" overflowAction="Discard">
      <target type="Database"
        dbProvider="System.Data.SqlServerCe.SqlCeConnection, System.Data.SqlServerCe, Version=3.5.1.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"
        connectionString="Data Source=${basedir}/SQLCEDB.sdf">

				<commandText>
          INSERT INTO ....
        </commandText>

		<parameter name="@time_stamp" layout="${date:format=yyyy-MM-dd HH\:mm\:ss.fff}" />
		<parameter name="@message" layout="${event-context:Message}" />
        <parameter name="@x" layout="${event-context:x}"/>
        <parameter name="@y" layout="${event-context:y}"/>
        <parameter name="@z" layout="${event-context:z}"/>
      </target>
		</target>
    <target name="Event" xsi:type="AsyncWrapper" queueLimit="500" overflowAction="Discard">
      <target type="Database"
        dbProvider="System.Data.SqlServerCe.SqlCeConnection, System.Data.SqlServerCe, Version=3.5.1.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"
        connectionString="Data Source=${basedir}/SQLCEDB.sdf">

        <commandText>
          INSERT INTO ....
        </commandText>

        <parameter name="@time_stamp" layout="${date:format=yyyy-MM-dd HH\:mm\:ss.fff}" />
        <parameter name="@message" layout="${event-context:Message}" />
        <parameter name="@a" layout="${event-context:a}"/>
        <parameter name="@b" layout="${event-context:b}"/>
        <parameter name="@c" layout="${event-context:c}"/>
      </target>
    </target>
   
	</targets>

	<rules>
		<logger name="file" minlevel="Debug" writeTo="file" />

		<logger name="Order" minlevel="Debug" writeTo="Order" />
		<logger name="Event" minlevel="Debug" writeTo="Event" />

	</rules>
</nlog>

Reply | Threaded
Open this post in threaded view
|

Re: multiple database tables

maxh
Nevermind, I figured it out. I had a silly typo in my c# code.
Reply | Threaded
Open this post in threaded view
|

Re: multiple database tables

Harsha
In reply to this post by maxh
Do you have a sample code for this like how to call multiple targets in code for multiple tables.