Logging DML operations in ASP NET MVC project

0 votes
There are several ways to log dml activities like as insert, update, and delete in an asp.net mvc project. I'm not sure if using aspects in code, triggers, or CDC in the database server is more useful, or if there are other, more logical options.
Jun 11 in C# by krishna
• 1,340 points
11 views

1 answer to this question.

0 votes

There are several options.

You might register an application interceptor if you're using Entity Framework as your ORM (see IDbCommandInterceptor). For further information, see Logging and intercepting database activities...

Setting the Database is another way that is very useful for logging ALL database operations.

Assign the following property to your DbContext implementation:

public class YourContext : DbContext
{   
    public YourContext(ILogger<YourContext> logger)
    {
        Database.Log = sql => logger.LogDebug(sql);
    }
}

I found this approach to be quite useful for debugging. I would have a file appender/target/sink (depending on what logging framework you're using e.g. NLog/Log4net/Serilog) specifically for my DbContext implementation, so that I could easily see the SQL of the database operations that are being executed without any noise from other application logs.

The other approach that I've used quite a bit is to use SQL Server Profiler, but this assumes a) you're using SQL Server, and b) you're able to connect to the database server.

answered Jun 14 by jyoti
• 1,240 points

Related Questions In C#

0 votes
1 answer

How to send email in ASP.NET C#

You can try this using Hotmail like ...READ MORE

answered Jun 14 in C# by krishna
• 1,340 points
11 views
0 votes
1 answer

A good and complete tutorial about reflection in .NET?

First, go to this link http://www.codeproject.com/Articles/55710/Reflection-in-NET Also, you ...READ MORE

answered Jun 6 in C# by pranav
• 2,320 points
20 views
0 votes
1 answer
0 votes
1 answer

How do I specify the exit code of a console application in .NET

Simply put, you can return the exit ...READ MORE

answered Jun 11 in C# by pranav
• 2,320 points
20 views
0 votes
1 answer

Embedding Power Bi Report Promise is not defined powerbi.js

IE does not yet support Promise. You ...READ MORE

answered Oct 30, 2018 in Power BI by Shubham
• 13,490 points
1,155 views
0 votes
0 answers

The page cannot be displayed because an internal server error has occurred on server

When  I've deployed the website I installed  ...READ MORE

May 23 in Others by Kichu
• 19,040 points
75 views
0 votes
1 answer

Examples of dynamic polymorphism in c#

Check the example of polymorphism below. We ...READ MORE

answered Jun 7 in C# by pranav
• 2,320 points
12 views
0 votes
1 answer

Reading a key from the Web.Config using ConfigurationManager

Instead of any other thing, use the ...READ MORE

answered Jun 11 in C# by pranav
• 2,320 points
15 views
0 votes
1 answer

Awesome ASP.NET and C# tutorials for beginners

Go here https://dotnet.microsoft.com/en-us/learn/aspnet They have some nice tutorials ...READ MORE

answered Jun 17 in C# by jyoti
• 1,240 points
16 views
0 votes
1 answer

Beginners book for .NET and C#

It depends on how proficient you are ...READ MORE

answered Jun 21 in C# by jyoti
• 1,240 points
10 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP