1

I have an ASP.NET web application written with C#. It uses SQL Server 2008 database. It seems that some of the SQL queries are deadlocking the SQL server and I'm also experiencing bad SQL Server performance. To find out which, I thought to add a diagnostic event logging, but I'm not sure how. If I was writing a plain Windows application, I'd do that with the Windows Event Log, or with just a simple text file. So I'm curious, how to do the same from a web application?

2

3 Answers 3

3

There are many options for logging from an ASP.Net web application.

NLog is one worthy of consideration because it performs well and offers a wide range of log targets based on severity including text file, database, email, or a GUI log viewer such as Sentinel.

Having said that, application-level logging is probably not the best way to diagnose specifically SQL Server deadlocks. I would suggest starting with SQL Server Profiler for that task

Analyzing Deadlocks with SQL Server Profiler

Sign up to request clarification or add additional context in comments.

1 Comment

I agree with @ErikJ NLog and Log4Net are great solutions.
1

.NET has build in loggin system with rich features and flexible configuration since version 2.0. You can start with this article on MSDN For some reason most people do not use it though and prefer either Log4net or NLog for logging. First is port of java logging tool and second is rethinking of it. I personally prefer to use TraceSource with filters. ADO.NET natively support it as well.

7 Comments

Good deal. Where is that built-in log saved -- file system file, or database?
@c00000fd wherever you configure it to be saved. Here is information on listeners msdn.microsoft.com/en-us/library/4y5y10s7.aspx
IMHO the built-in logging framework lacks the completeness of a solution like NLog or Log4Net.
@EricJ. can you give an example ?
Example: What do you have to do to with the built-in frameworks to write Critical & error items to a text file, database and email address; warning items to a text file & database, and other items just to a text file, but for the debug build also write everything to a GUI based viewer to facilitate development? With NLog it's just a few lines of configuration.
|
0

Deadlocking occurs on the SQL side, it's impossible for ASP.NET to be aware of the full picture.

I recommend checking your queries for a WITH LOCK statement and before removing it figuring out why it's there to begin with.

Otherwise, if you find an offending query via SQL server Diagnostics manager... or if you can reproduce the deadlock purely on the SQL side, add WITH NOLOCK to that query. T

his is by far the simplest solution, better solutions involve getting to the root cause of why the deadlock is occurring in the first place.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.