Entering razor view in MVC3

How to add a record to a razor? I would like to add debug statements using a logging tool like log4net?

+3
source share
3 answers

I agree with the other answers, but that would be to debug such search counts or similar scenarios.

After a little twist, the syntax worked.

@{ ViewBag.Log = log4net.LogManager.GetLogger("Products.cshtml");}

@ViewBag.Log.Debug("Products count = " + Model.Products.ToList().Count);

Hope this helps someone.

+5
source

I strongly discourage you from this.

It seems to me that you have logic in your views. This makes it difficult to maintain views and even more difficult to verify logic.

Move the logic to either the controllers or the view model. And register them instead.

+4
source

It looks like you might be better off using an application broadcast approach, since you don't want to catch logical errors in your view. Logic should be in controllers and (to some extent) models.

Take a look here → fooobar.com/questions/1820885 / ... to learn how to log errors and catch exceptions on your site.

+1
source

All Articles