Database Target Not Working

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

Database Target Not Working

Jack
I am trying to write to a sql server 2005 database from a wcf service
here is the target definition in the config file, when I run in debug all I get is an exception error. If I write to a local file it works just fine. Any Suggestions

    <target name="EventManagementServiceTransactionLog"
            xsi:type="Database"
            dbProvider="sqlserver"
            connectionString="Data Source=JDAVID;Initial Catalog=DBC_SYSTEM_MANAGEMENT;Integrated Security=True">
      <commandText>
        INSERT INTO Event_Management_Service_Transaction_Log
        (LoggerLevel,
        LoggerName,
        Message,
        TransactionDateTime)
        Values
        (@Level,
        @Logger,
        @Message,
        @DataTime);
      </commandText>
      <parameter name ="@DateTime" layout="${date}" />
      <parameter name ="@Level" layout="${level}" />
      <parameter name ="@Logger" layout="${logger}" />
      <parameter name ="@message" layout="${message}" />
    </target>
Reply | Threaded
Open this post in threaded view
|

Re: Database Target Not Working

vyas
Hi

instead of using  dbProvider="sqlserver"  try  dbProvider="mssql"

this might solve your problem.



Go Big or Go Home
Regards,
Vyas



Vyas
Reply | Threaded
Open this post in threaded view
|

Re: Database Target Not Working

Jack
Tried that and it did not work....
Reply | Threaded
Open this post in threaded view
|

Re: Database Target Not Working

Darren
I've been struggling with the very same issue for a couple of hours now. Let me know if you can get a solution working for logging to a SQL Server database. I'm new to NLog and I can't believe such a standard logging feature can be so difficult to setup.

(I'm using SQLServer2008 Express)

The exception error I am getting is:
System.ArgumentException: Format of the initialization string does not conform to specification starting at index 0.

My NLog.Config file looks like:

    <target name="databaselog" xsi:type="Database">

      <dbProvider>sqlserver</dbProvider>

     
     
      <connectionString>Data Source=MYSERVERNAME\SQLEXPRESS;Initial Catalog=SampleDatabase;Integrated Security=SSPI</connectionString>
     

      <commandText>
        insert into NLogError ([Message]) values (@message);
      </commandText>

      <parameter name="@message" layout="${message}" />       

    </target>
Reply | Threaded
Open this post in threaded view
|

Re: Database Target Not Working

Darren
Well I managed to figure out a solution for my problem.

The main reason I started looking into NLog was because the MVC starter kit by Rob Conery got me interested in it enough to see if it was better than Log4Net which I have used before.

The NLog.config file in the starter kit begins like this:

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

And it was those namespace declarations that caused the errors to occur.

I downloaded the nightly build of NLog and had a look at their example config file for database and it starts like this:

<?xml version="1.0" ?>
<nlog autoReload="true">

So by getting rid of the namespaces on the nlog tag I was able to get NLog writing to my database.

Hope this helps somebody else out.

Reply | Threaded
Open this post in threaded view
|

Re: Database Target Not Working

Jarek Kowalski
Administrator
This is totally unexpected - config file parser should not look at namespaces at all. Can you prepare a small repro file and file a bug on http://nlog.codeplex.com/ ?
 
Jarek
NLog Blog
Reply | Threaded
Open this post in threaded view
|

Re: Database Target Not Working

Jack
Darren
Thanks....but that did not seem to solve the problem, are you using version 2.0? I guess if I can't get this solved in the next day or so I will have to tell management that NLOG does not support the ability to log to a database and we will have to fine a different solution.
Reply | Threaded
Open this post in threaded view
|

Re: Database Target Not Working

Jarek Kowalski
Administrator
This is completely unexpected - logging to database is supported and many people are using it with success.
 
Did you go through troubleshooting steps?
 
Jarek
NLog Blog
Reply | Threaded
Open this post in threaded view
|

Re: Database Target Not Working

Alan Schrank
In reply to this post by Jack
Are you sure that the identity the web service is running under has access to the sql server and has insert rights?

I use NLog to log to Sql Server but I don't use integrated security.  You might try setting up a sql logon for a nloguser and then specify the userid and password in the nlog config.

What are the specifics of the exception you are getting?
Reply | Threaded
Open this post in threaded view
|

Re: Database Target Not Working

John Cullison
I'm having a similar issue.  I have targets to console, eventlog, and database.  The database one is not working.  When I enable internal logging, I get:

2010-08-13 09:47:05.8767 Debug AddTargetsFromAssembly('NLog, Version=1.0.0.505, Culture=neutral, PublicKeyToken=5120e14c03d0593c')
2010-08-13 09:47:05.9277 Trace Registering target FallbackGroup for type 'NLog.Targets.Compound.FallbackTarget')
2010-08-13 09:47:05.9277 Trace Registering target RandomizeGroup for type 'NLog.Targets.Compound.RandomizeTarget')
2010-08-13 09:47:05.9277 Trace Registering target RoundRobinGroup for type 'NLog.Targets.Compound.RoundRobinTarget')
2010-08-13 09:47:05.9277 Trace Registering target SplitGroup for type 'NLog.Targets.Compound.SplitTarget')
2010-08-13 09:47:05.9427 Trace Registering target ASPNetBufferingWrapper for type 'NLog.Targets.Wrappers.ASPNetBufferingTargetWrapper')
2010-08-13 09:47:05.9427 Trace Registering target AsyncWrapper for type 'NLog.Targets.Wrappers.AsyncTargetWrapper')
2010-08-13 09:47:05.9427 Trace Registering target AutoFlushWrapper for type 'NLog.Targets.Wrappers.AutoFlushTargetWrapper')
2010-08-13 09:47:05.9427 Trace Registering target BufferingWrapper for type 'NLog.Targets.Wrappers.BufferingTargetWrapper')
2010-08-13 09:47:05.9427 Trace Registering target FilteringWrapper for type 'NLog.Targets.Wrappers.FilteringTargetWrapper')
2010-08-13 09:47:05.9607 Trace Registering target ImpersonatingWrapper for type 'NLog.Targets.Wrappers.ImpersonatingTargetWrapper')
2010-08-13 09:47:05.9607 Trace Registering target PostFilteringWrapper for type 'NLog.Targets.Wrappers.PostFilteringTargetWrapper')
2010-08-13 09:47:05.9607 Trace Registering target RepeatingWrapper for type 'NLog.Targets.Wrappers.RepeatingTargetWrapper')
2010-08-13 09:47:05.9607 Trace Registering target RetryingWrapper for type 'NLog.Targets.Wrappers.RetryingTargetWrapper')
2010-08-13 09:47:05.9767 Trace Registering target ASPNetTrace for type 'NLog.Targets.ASPNetTraceTarget')
2010-08-13 09:47:05.9767 Trace Registering target Network for type 'NLog.Targets.NetworkTarget')
2010-08-13 09:47:05.9767 Trace Registering target NLogViewer for type 'NLog.Targets.NLogViewerTarget')
2010-08-13 09:47:05.9897 Trace Registering target Chainsaw for type 'NLog.Targets.ChainsawTarget')
2010-08-13 09:47:05.9897 Trace Registering target Console for type 'NLog.Targets.ConsoleTarget')
2010-08-13 09:47:05.9897 Trace Registering target Database for type 'NLog.Targets.DatabaseTarget')
2010-08-13 09:47:05.9897 Trace Registering target Debug for type 'NLog.Targets.DebugTarget')
2010-08-13 09:47:06.0077 Trace Registering target Debugger for type 'NLog.Targets.DebuggerTarget')
2010-08-13 09:47:06.0077 Trace Registering target File for type 'NLog.Targets.FileTarget')
2010-08-13 09:47:06.0077 Trace Registering target FormControl for type 'NLog.Targets.FormControlTarget')
2010-08-13 09:47:06.0217 Trace Registering target Mail for type 'NLog.Targets.MailTarget')
2010-08-13 09:47:06.0217 Trace Registering target Memory for type 'NLog.Targets.MemoryTarget')
2010-08-13 09:47:06.0217 Trace Registering target MessageBox for type 'NLog.Targets.MessageBoxTarget')
2010-08-13 09:47:06.0357 Trace Registering target MethodCall for type 'NLog.Targets.MethodCallTarget')
2010-08-13 09:47:06.0357 Trace Registering target Null for type 'NLog.Targets.NullTarget')
2010-08-13 09:47:06.0357 Trace Registering target RichTextBox for type 'NLog.Targets.RichTextBoxTarget')
2010-08-13 09:47:06.0357 Trace Registering target Trace for type 'NLog.Targets.TraceTarget')
2010-08-13 09:47:06.0557 Trace Registering target WebService for type 'NLog.Targets.WebServiceTarget')
2010-08-13 09:47:06.0557 Trace Registering target ASPResponse for type 'NLog.Win32.Targets.ASPResponseTarget')
2010-08-13 09:47:06.0557 Trace Registering target ColoredConsole for type 'NLog.Win32.Targets.ColoredConsoleTarget')
2010-08-13 09:47:06.0717 Trace Registering target EventLog for type 'NLog.Win32.Targets.EventLogTarget')
2010-08-13 09:47:06.0717 Trace Registering target MSMQ for type 'NLog.Win32.Targets.MSMQTarget')
2010-08-13 09:47:06.0717 Trace Registering target OutputDebugString for type 'NLog.Win32.Targets.OutputDebugStringTarget')
2010-08-13 09:47:06.0877 Trace Registering target PerfCounter for type 'NLog.Win32.Targets.PerfCounterTarget')
2010-08-13 09:47:06.1087 Debug Setting 'DatabaseTarget.name' to 'errorlogtable'
2010-08-13 09:47:06.1147 Debug Setting 'DatabaseTarget.dbProvider' to 'MySql.Data.MySqlClient'
2010-08-13 09:47:06.1147 Debug Setting 'DatabaseTarget.keepConnection' to 'true'
2010-08-13 09:47:06.1147 Debug Setting 'DatabaseTarget.commandText' to 'INSERT INTO DataProcessingErrorLog (EVENT_LEVEL, TIME_STAMP, EVENT_MESSAGE) VALUES (@level, @timestamp, @message)'
2010-08-13 09:47:06.1317 Debug Setting 'DatabaseTarget.connectionString' to 'Data Source=192.168.1.119;Initial Catalog=CM;Persist Security Info=True;User ID=CM_USER;Password=Security#1'
2010-08-13 09:47:06.1317 Debug Setting 'DatabaseParameterInfo.name' to '@level'
2010-08-13 09:47:06.1467 Debug Setting 'DatabaseParameterInfo.layout' to '${level}'
2010-08-13 09:47:06.1467 Debug AddLayoutRenderersFromAssembly('NLog, Version=1.0.0.505, Culture=neutral, PublicKeyToken=5120e14c03d0593c')
2010-08-13 09:47:06.1847 Trace Registering layout renderer aspnet-application for type 'NLog.LayoutRenderers.ASPNETApplicationValueLayoutRenderer')
2010-08-13 09:47:06.1847 Trace Registering layout renderer aspnet-request for type 'NLog.LayoutRenderers.ASPNETRequestValueLayoutRenderer')
2010-08-13 09:47:06.1967 Trace Registering layout renderer aspnet-session for type 'NLog.LayoutRenderers.ASPNETSessionValueLayoutRenderer')
2010-08-13 09:47:06.1967 Trace Registering layout renderer aspnet-sessionid for type 'NLog.LayoutRenderers.ASPNETSessionIDLayoutRenderer')
2010-08-13 09:47:06.2077 Trace Registering layout renderer aspnet-user-authtype for type 'NLog.LayoutRenderers.ASPNETUserAuthTypeLayoutRenderer')
2010-08-13 09:47:06.2077 Trace Registering layout renderer aspnet-user-identity for type 'NLog.LayoutRenderers.ASPNETUserIdentityLayoutRenderer')
2010-08-13 09:47:06.2077 Trace Registering layout renderer basedir for type 'NLog.LayoutRenderers.BaseDirLayoutRenderer')
2010-08-13 09:47:06.2267 Trace Registering layout renderer callsite for type 'NLog.LayoutRenderers.CallSiteLayoutRenderer')
2010-08-13 09:47:06.2267 Trace Registering layout renderer counter for type 'NLog.LayoutRenderers.CounterLayoutRenderer')
2010-08-13 09:47:06.2387 Trace Registering layout renderer date for type 'NLog.LayoutRenderers.DateLayoutRenderer')
2010-08-13 09:47:06.2387 Trace Registering layout renderer environment for type 'NLog.LayoutRenderers.EnvironmentLayoutRenderer')
2010-08-13 09:47:06.2387 Trace Registering layout renderer event-context for type 'NLog.LayoutRenderers.EventContextLayoutRenderer')
2010-08-13 09:47:06.2577 Trace Registering layout renderer exception for type 'NLog.LayoutRenderers.ExceptionLayoutRenderer')
2010-08-13 09:47:06.2577 Trace Registering layout renderer file-contents for type 'NLog.LayoutRenderers.FileContentsLayoutRenderer')
2010-08-13 09:47:06.2707 Trace Registering layout renderer gc for type 'NLog.LayoutRenderers.GCLayoutRenderer')
2010-08-13 09:47:06.2707 Trace Registering layout renderer gdc for type 'NLog.LayoutRenderers.GDCLayoutRenderer')
2010-08-13 09:47:06.2707 Trace Registering layout renderer guid for type 'NLog.LayoutRenderers.GuidLayoutRenderer')
2010-08-13 09:47:06.2907 Trace Registering layout renderer identity for type 'NLog.LayoutRenderers.IdentityLayoutRenderer')
2010-08-13 09:47:06.2907 Trace Registering layout renderer level for type 'NLog.LayoutRenderers.LevelLayoutRenderer')
2010-08-13 09:47:06.3037 Trace Registering layout renderer literal for type 'NLog.LayoutRenderers.LiteralLayoutRenderer')
2010-08-13 09:47:06.3037 Trace Registering layout renderer log4jxmlevent for type 'NLog.LayoutRenderers.Log4JXmlEventLayoutRenderer')
2010-08-13 09:47:06.3037 Trace Registering layout renderer logger for type 'NLog.LayoutRenderers.LoggerNameLayoutRenderer')
2010-08-13 09:47:06.3227 Trace Registering layout renderer longdate for type 'NLog.LayoutRenderers.LongDateLayoutRenderer')
2010-08-13 09:47:06.3227 Trace Registering layout renderer machinename for type 'NLog.LayoutRenderers.MachineNameLayoutRenderer')
2010-08-13 09:47:06.3357 Trace Registering layout renderer mdc for type 'NLog.LayoutRenderers.MDCLayoutRenderer')
2010-08-13 09:47:06.3357 Trace Registering layout renderer message for type 'NLog.LayoutRenderers.MessageLayoutRenderer')
2010-08-13 09:47:06.3357 Trace Registering layout renderer ndc for type 'NLog.LayoutRenderers.NDCLayoutRenderer')
2010-08-13 09:47:06.3526 Trace Registering layout renderer newline for type 'NLog.LayoutRenderers.NewLine')
2010-08-13 09:47:06.3526 Trace Registering layout renderer nlogdir for type 'NLog.LayoutRenderers.NLogDirLayoutRenderer')
2010-08-13 09:47:06.3646 Trace Registering layout renderer performancecounter for type 'NLog.LayoutRenderers.PerformanceCounterLayoutRenderer')
2010-08-13 09:47:06.3646 Trace Registering layout renderer processid for type 'NLog.LayoutRenderers.ProcessIDLayoutRenderer')
2010-08-13 09:47:06.3646 Trace Registering layout renderer processinfo for type 'NLog.LayoutRenderers.ProcessInfoLayoutRenderer')
2010-08-13 09:47:06.3816 Trace Registering layout renderer processname for type 'NLog.LayoutRenderers.ProcessNameLayoutRenderer')
2010-08-13 09:47:06.3816 Trace Registering layout renderer processtime for type 'NLog.LayoutRenderers.ProcessTimeLayoutRenderer')
2010-08-13 09:47:06.3816 Trace Registering layout renderer qpc for type 'NLog.LayoutRenderers.QpcLayoutRenderer')
2010-08-13 09:47:06.3996 Trace Registering layout renderer rot13 for type 'NLog.LayoutRenderers.Rot13LayoutRenderer')
2010-08-13 09:47:06.3996 Trace Registering layout renderer shortdate for type 'NLog.LayoutRenderers.ShortDateLayoutRenderer')
2010-08-13 09:47:06.4106 Trace Registering layout renderer specialfolder for type 'NLog.LayoutRenderers.SpecialFolderLayoutRenderer')
2010-08-13 09:47:06.4106 Trace Registering layout renderer stacktrace for type 'NLog.LayoutRenderers.StackTraceLayoutRenderer')
2010-08-13 09:47:06.4106 Trace Registering layout renderer tempdir for type 'NLog.LayoutRenderers.TempDirLayoutRenderer')
2010-08-13 09:47:06.4286 Trace Registering layout renderer threadid for type 'NLog.LayoutRenderers.ThreadIDLayoutRenderer')
2010-08-13 09:47:06.4286 Trace Registering layout renderer threadname for type 'NLog.LayoutRenderers.ThreadNameLayoutRenderer')
2010-08-13 09:47:06.4286 Trace Registering layout renderer ticks for type 'NLog.LayoutRenderers.TicksLayoutRenderer')
2010-08-13 09:47:06.4466 Trace Registering layout renderer asp-application for type 'NLog.Win32.LayoutRenderers.ASPApplicationValueLayoutRenderer')
2010-08-13 09:47:06.4466 Trace Registering layout renderer asp-request for type 'NLog.Win32.LayoutRenderers.ASPRequestValueLayoutRenderer')
2010-08-13 09:47:06.4586 Trace Registering layout renderer asp-session for type 'NLog.Win32.LayoutRenderers.ASPSessionValueLayoutRenderer')
2010-08-13 09:47:06.4586 Trace Registering layout renderer registry for type 'NLog.Win32.LayoutRenderers.RegistryLayoutRenderer')
2010-08-13 09:47:06.4586 Trace Registering layout renderer windows-identity for type 'NLog.Win32.LayoutRenderers.WindowsIdentityLayoutRenderer')
2010-08-13 09:47:06.4786 Debug Setting 'DatabaseParameterInfo.name' to '@timestamp'
2010-08-13 09:47:06.4786 Debug Setting 'DatabaseParameterInfo.layout' to '${date}'
2010-08-13 09:47:06.4906 Debug Setting 'DatabaseParameterInfo.name' to '@message'
2010-08-13 09:47:06.4906 Debug Setting 'DatabaseParameterInfo.layout' to '${message}'
2010-08-13 09:47:06.4906 Info Adding target errorlogtable:DatabaseTarget
2010-08-13 09:47:06.5086 Debug Registering target errorlogtable: NLog.Targets.DatabaseTarget
2010-08-13 09:47:06.5086 Debug Setting 'LevelLayoutRenderer.uppercase' to 'true'
2010-08-13 09:47:06.5236 Debug Setting 'ConsoleTarget.name' to 'console'
2010-08-13 09:47:06.5236 Debug Setting 'ConsoleTarget.layout' to '${message}'
2010-08-13 09:47:06.5356 Info Adding target console:ConsoleTarget
2010-08-13 09:47:06.5356 Debug Registering target console: NLog.Targets.ConsoleTarget
2010-08-13 09:47:06.5356 Debug Setting 'LevelLayoutRenderer.uppercase' to 'true'
2010-08-13 09:47:06.5536 Debug Setting 'EventLogTarget.name' to 'eventlog'
2010-08-13 09:47:06.5536 Debug Setting 'EventLogTarget.layout' to '${logger}: ${message}'
2010-08-13 09:47:06.5536 Debug Setting 'EventLogTarget.source' to 'IndustrialDefenderComplianceManager'
2010-08-13 09:47:06.5716 Debug Setting 'EventLogTarget.log' to 'Application'
2010-08-13 09:47:06.5716 Info Adding target eventlog:EventLogTarget
2010-08-13 09:47:06.5836 Debug Registering target eventlog: NLog.Win32.Targets.EventLogTarget
2010-08-13 09:47:06.5836 Debug Setting 'AsyncTargetWrapper.name' to 'asyncFile'
2010-08-13 09:47:06.5836 Debug Setting 'LevelLayoutRenderer.uppercase' to 'true'
2010-08-13 09:47:06.6016 Debug Setting 'FileTarget.name' to 'traceFile'
2010-08-13 09:47:06.6016 Debug Setting 'FileTarget.fileName' to 'C:\TEMP\TraceFile.TXT'
2010-08-13 09:47:06.6136 Debug Registering target traceFile: NLog.Targets.FileTarget
2010-08-13 09:47:06.6136 Info Adding target asyncFile:AsyncTargetWrapper(traceFile:FileTarget)
2010-08-13 09:47:06.6136 Debug Registering target asyncFile: NLog.Targets.Wrappers.AsyncTargetWrapper
2010-08-13 09:47:06.6366 Debug --- NLog configuration dump. ---
2010-08-13 09:47:06.6366 Debug Targets:
2010-08-13 09:47:06.6486 Info traceFile:FileTarget
2010-08-13 09:47:06.6486 Info eventlog:EventLogTarget
2010-08-13 09:47:06.6596 Info asyncFile:AsyncTargetWrapper(traceFile:FileTarget)
2010-08-13 09:47:06.6596 Info console:ConsoleTarget
2010-08-13 09:47:06.6596 Info errorlogtable:DatabaseTarget
2010-08-13 09:47:06.6766 Debug Rules:
2010-08-13 09:47:06.6766 Info logNamePattern: (DataProcessor:Equals) levels: [ ] appendTo: [ errorlogtable ]
2010-08-13 09:47:06.6766 Info logNamePattern: (DataProcessor:Equals) levels: [ ] appendTo: [ eventlog ]
2010-08-13 09:47:06.6956 Info logNamePattern: (DataProcessor:Equals) levels: [ Trace Debug Info Warn Error Fatal ] appendTo: [ console ]
2010-08-13 09:47:06.6956 Info logNamePattern: (DataProcessor:Equals) levels: [ Trace Debug Info Warn Error Fatal ] appendTo: [ asyncFile ]
2010-08-13 09:47:06.7076 Debug --- End of NLog configuration dump ---
2010-08-13 09:47:06.7076 Info Watching path 'c:\atlas1\src\dataprocessor\bin\debug' filter 'nlog.config' for changes.
2010-08-13 09:47:06.7266 Debug Starting lazy writer timer...
2010-08-13 09:47:06.7386 Debug Targets for DataProcessor by level:
2010-08-13 09:47:06.7386 Debug Trace => console
2010-08-13 09:47:06.7386 Debug Debug => console
2010-08-13 09:47:06.7566 Debug Info => errorlogtable console
2010-08-13 09:47:06.7566 Debug Warn => errorlogtable console
2010-08-13 09:47:06.7566 Debug Error => errorlogtable eventlog console
2010-08-13 09:47:06.7736 Debug Fatal => errorlogtable eventlog console
2010-08-13 09:47:06.7876 Error Target exception: System.NullReferenceException: Object reference not set to an instance of an object.
   at NLog.Targets.DatabaseTarget.OpenConnection(LogEventInfo logEvent)
   at NLog.Targets.DatabaseTarget.Write(LogEventInfo logEvent)
   at NLog.LoggerImpl.Write(Type loggerType, TargetWithFilterChain targets, LogEventInfo logEvent, LogFactory factory)

My NLog.config file is as follows:

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

<nlog internalLogFile="C:\TEMP\nlogint.txt" internalLogLevel="Trace" autoReload="true">
    <targets>
        <target name="errorlogtable" type="Database" dbProvider="MySql.Data.MySqlClient" keepConnection="true"
        commandText="INSERT INTO DataProcessingErrorLog (EVENT_LEVEL, TIME_STAMP, EVENT_MESSAGE) VALUES (@level, @timestamp, @message)"
        connectionString="Data Source=192.168.1.119;Initial Catalog=CM;Persist Security Info=True;User ID=CM_USER;Password=Security#1"
        >
        <parameter name="@level" layout="${level}" />
        <parameter name="@timestamp" layout="${date}" />
        <parameter name="@message" layout="${message}" />
        </target>
        <target name="console" type="Console" layout="${message}" />
        <target name="eventlog" type="EventLog" layout="${logger}: ${message}"
        source="IndustrialDefenderComplianceManager" log="Application" />
        <target name="asyncFile" type="AsyncWrapper">
            <target name="traceFile" type="File" fileName="C:\TEMP\TraceFile.TXT" />
        </target>
    </targets>
    <rules>
        <logger name="DataProcessor" minlevel="Info" writeTo="errorlogtable" />
        <logger name="DataProcessor" minlevel="Error" writeTo="eventlog" />
        <logger name="DataProcessor" minlevel="Trace" writeTo="console" final="true" />
        <logger name="DataProcessor" minlevel="Trace" writeTo="asyncFile" />
    </rules>
</nlog>

The connection string offered is copied verbatim from the other config file used by the application (which is used to open connections successfully and write loads of data to the database), so I'm fairly confident that it's correct.

Any guesses as to what's happening?

(Note: I've tried it with the namespace indicated and recently without.  No database entries are written regardless.)
Reply | Threaded
Open this post in threaded view
|

Re: Database Target Not Working

John Cullison
OK, I'm not sure why the SQL Server support requires tags instead of attributes (when I was using the xsi namespace, the various database-related attributes were offered when I created the database target, so...), but indeed, changing the attributes to tags works:

        <target name="errorlogtable" type="Database">
                <dbprovider>mssql</dbprovider>
                <connectionstring>Data Source=192.168.1.119;Initial Catalog=CM;Persist Security Info=True;User ID=CM_USER;Password=Security#1</connectionstring>
                <commandText>INSERT INTO DataProcessingErrorLog (EVENT_LEVEL, TIME_STAMP, EVENT_MESSAGE) VALUES (@level, @timestamp, @message)</commandText>
                <parameter name="@level" layout="${level}" />
                <parameter name="@timestamp" layout="${date}" />
                <parameter name="@message" layout="${message}" />
        </target>
Reply | Threaded
Open this post in threaded view
|

Re: Database Target Not Working

harry180
This post was updated on .
@John Cullison you don't need to write tags u can use attribute

<target name="errorlogtable" xsi:type="Database"
              connectionString="Data Source=192.168.1.119;Initial Catalog=CM;Persist Security Info=True;User ID=CM_USER;Password=Security#1"
              keepConnection="true" dbProvider="sqlServer" commandText="INSERT INTO DataProcessingErrorLog (EVENT_LEVEL, TIME_STAMP, EVENT_MESSAGE) VALUES (@level, @timestamp, @message)" >
<parameter name="@level" layout="${level}" />
                <parameter name="@timestamp" layout="${date}" />
                <parameter name="@message" layout="${message}" />
        </target>

pls let me know if that help.