<target name="DatabaseLog" xsi:type="Database" connectionString="XXXX">
<commandText>
insert into LogTable(time_stamp,level,logger,message) values(@time_stamp, @level, @logger, @message);
</commandText>
<parameter name="@time_stamp" layout="${date}" />
<parameter name="@level" layout="${level}" />
<parameter name="@logger" layout="${logger}" />
<parameter name="@message" layout="${message}" />
On building the application, it highlights the 'commandText' text and the message is 'The element cannot contain text. Content model is empty'.
Any help would be appreciated.
Thanks
Hi Simon,
The command text should not be entered in an element, it is an attribute on the target element.
See https://github.com/NLog/NLog/wiki/Database-target
--
You received this message because you are subscribed to a topic in the Google Groups "NLog-Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/nlog-users/rlzoOJyQ8Nw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to nlog-users+...@googlegroups.com.
To post to this group, send email to nlog-...@googlegroups.com.
Visit this group at http://groups.google.com/group/nlog-users.
For more options, visit https://groups.google.com/d/optout.
Instead of using the connectionstring attribute, you should use the connectionstringname attribute passing in the name of the connection string.
Rich,I use the following code to loop through looking for all database targets. If you have a specific named target, you could be a little more efficient in retrieving the target.NLog.Config.LoggingConfiguration config = LogManager.Configuration; if (null != config) { System.Diagnostics.Debug.WriteLine("SqlHelper: Initialize Logger - Config found"); LogManager.ThrowExceptions = false; // Get connection strings for the current application SqlConnectionStringBuilder csbApplication = new SqlConnectionStringBuilder();
csbApplication.ConnectionString = myApplication.getConnection().ConnectionString;
foreach (Target t in config.AllTargets) { SqlConnectionStringBuilder csb = null; System.Diagnostics.Debug.WriteLine("SqlHelper: Initialize Logger - Target found"); DatabaseTarget dt = t as DatabaseTarget; if (null != dt) { System.Diagnostics.Debug.WriteLine("SqlHelper: Initialize Logger - Database target found"); // Get connection string from dddd if (dt.Name.Equals("MySpecialDbLog")) { csb = csbSpecialApplication; } else { csb = csbApplication; } if (null != csb) { System.Diagnostics.Debug.WriteLine(string.Format("SqlHelper: Initialize Logger - Connection string set to {0}", csb.ToString())); } System.Diagnostics.Debug.WriteLine("SqlHelper: Initialize Logger - Setting connection string to stored value"); // Set the connection string. dt.ConnectionString = csb.ToString(); } System.Diagnostics.Debug.WriteLine("SqlHelper: Initialize Logger - Reset configuration"); // Set new logging configuration LogManager.Configuration = config;}}}I hope this helps.--G
--
You received this message because you are subscribed to the Google Groups "NLog-Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nlog-users+...@googlegroups.com.
Thank you so much! Yes, this fixed it. To assist anyone else who may run into a similar situation I am including my NLog.config below. "Logger" refers to the connectionString in my Web.config file:
"connectionStringName - Name of the connection string (as specified in . "
Could you please finish that sentence for me?--