I have been trying to track down a performance problem today on an ASP.NET MVC. It all turned out to be down to an incorrect connection string in a nLog.config file for logging to a SQL DB. As soon as I commented out the Db target for nLog my login to the web site was virtually instant as opposed to taking 30 seconds (what i assume is a SQL timeout)
I had suspected a problem with the logged as I was not seeing anything in DebugView, but it all took a while to track down as i did not seem to get any logging output.
It seems the blocker was if I had Visual Studio 2012 running in debug mode then any output to the OutputDebugString was lost, this took forever to realise. The only truly reliable target was that of a text file. I had expected the logging messages to appear in the VS debug window – it did not.
So this is what worked as a user who is a local administrator, but with UAC enable and NOT running any of the tools as administrator (so nothing special).
- Load DebugView with default settings.
- From in VS2012 start the web site without debugging (so it loads IIS Express and IE)
- Load the web page with some logging
- The logging appears in the file, debugview and the DB
This was done using the nlog.config file
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
<target xsi:type=“Database” name=“db”
commandText=“INSERT INTO [LogEntries](TimeStamp, Message, Level, Logger) VALUES(getutcdate(), @msg, @level, @logger)”
connectionString=“server=.sql2012;database=MyDb;integrated security=sspi” dbProvider=“System.Data.SqlClient” >
<target xsi:type=“File” name=“f” fileName="${basedir}/logs/${shortdate}.log"
layout="${longdate} ${uppercase:${level}} ${message}" />