Note that there are some explanatory texts on larger screens.

plurals
  1. POnLog and TransactionScope
    primarykey
    data
    text
    <p>I have an ASP.NET MVC 3 (using Entity Framework 4.2) application that uses transactions as follows:</p> <pre><code>using (var transaction = new TransactionScope()) { // Database action 1 // Database action 2 context.SaveChanges(); Logger.Info("Record X updated"); transaction.Complete(); } </code></pre> <p>I get no errors, but no data is written to the database. However, the log file target (there just for testing purposes) works fine. Here is my nLog (I'm using v2) config:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt; &lt;nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" throwExceptions="true" internalLogToConsole="true" internalLogToConsoleError="true" &gt; &lt;targets&gt; &lt;target name="logfile" xsi:type="File" fileName="${basedir}app_data\file.txt" /&gt; &lt;target xsi:type="Database" name="database"&gt; &lt;commandText&gt;INSERT INTO [LogEntries] (TimeStamp, Message, Level, Logger) VALUES(GETDATE(), @msg, @level, @logger)&lt;/commandText&gt; &lt;parameter name="@msg" layout="${message}" /&gt; &lt;parameter name="@level" layout="${level}" /&gt; &lt;parameter name="@logger" layout="${logger}" /&gt; &lt;dbProvider&gt;System.Data.SqlServerCe.4.0&lt;/dbProvider&gt; &lt;connectionString&gt;Data Source=${basedir}app_data\Logger.sdf&lt;/connectionString&gt; &lt;/target&gt; &lt;/targets&gt; &lt;rules&gt; &lt;logger name="*" minlevel="Trace" writeTo="logfile" /&gt; &lt;logger name="*" minlevel="Trace" writeTo="database" /&gt; &lt;/rules&gt; &lt;/nlog&gt; </code></pre> <p>If I move the Logger line outside of the transactionscope it works fine. So I think it's something to do with this. I'm using SQL Server 2008 r2 for my main database and SQL Compact 4 for my logging database. Also, I've tried adding useTranscations="true".</p> <p>Any ideas what I'm doing wrong?</p> <p>Thanks </p> <p>Alan</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload