Thursday, December 5, 2013

How to Configure ASP.NET Tracing for ASP.NET MVC Applications

  1. ASP.NET Application Level Tracing
  2. Writting Custom ASP.NET Trace Messages using System.Diagnostics.TraceSource class and trace sources
  3. Writting Custom ASP.NET Trace Messages using System.Diagnostics.Trace class
PRE-Requisite(Trace Complier Constant) : Trace statements (Custom tracing) require the TRACE compiler constant, but it’s on by default and you can verify that in the Build tab of the project properties window
The problem is that this setting in the .csproj file only applies to .cs files. ASP.NET uses a different compile process for .cshtml files (or .aspx files in Web Forms), and the settings for that compile process are in the Web.config file. If you don’t explicitly specify the TRACE constant there, tracing method calls in .cshtml views are ignored. Below is an example of what you have to add to the application Web.config file for a Visual Studio project that targets .NET 4.5, in order to define a TRACE constant for the .cshtml compiler:
 
   
     
     
   
 

ASP.NET Application Level Tracing

Web.Config entries

  
    
  


    
       
      
      
      
    
    
        
         
          
          
          
                   
         
       
      
        
          
          
          
        
          
    
    
      
      
    
    
      
        
        
      
    
  
C# Code
 using System.Diagnostics;
 public class AccountController : Controller
    {
        public ActionResult Index()
        {            
            TraceSource source = new TraceSource("AccountController");
            source.TraceEvent(TraceEventType.Warning, 100, "This is message logged from Account Controller");
            return View();
        }

    }
Writting Custom ASP.NET Trace Messages using System.Diagnostics.Trace class
 using System.Diagnostics;
 public class AccountController : Controller
    {
        public ActionResult Index()
        {          
            Trace.WriteLine("This is message logged from Account Controller");
            return View();
        }

    }

24 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. You blog post is just completely quality and informative. Many new facts and information which I have not heard about before. Keep sharing more blog posts.
    python training in tambaram | python training in annanagar | python training in jayanagar

    ReplyDelete
  3. All the points you described so beautiful. Every time i read your i blog and i am so surprised that how you can write so well.
    Java training in Tambaram | Java training in Velachery

    Java training in Omr | Oracle training in Chennai

    ReplyDelete
  4. Good Post, I am a big believer in posting comments on sites to let the blog writers know that they ve added something advantageous to the world wide web.

    devops online training

    aws online training

    data science with python online training

    data science online training

    rpa online training

    ReplyDelete
  5. Thanks for sharing such an awesome Information with us

    I Got Job in my dream company with decent 12 Lacks Per Annum salary, I have learned this world most demanding course out there in the current IT Market from the Big Data Training In Bangalore Providers who helped me a lot to achieve my dreams comes true. Really worth trying.

    ReplyDelete
  6. Existing without the answers to the difficulties you’ve sorted out through this guide is a critical case, as well as the kind which could have badly affected my entire career if I had not discovered your website.
    Best PHP Training Institute in Chennai|PHP Course in chennai

    Best .Net Training Institute in Chennai
    Big Data Hadoop Training in Chennai
    Linux Training in Chennai
    Cloud Computing Training in Chennai

    ReplyDelete
  7. Excellent information on your blog, thank you for taking the time to share with us. Amazing insight you have on this, it's nice to find a website the details so much information
    Java Training in Chennai

    Java Training in Velachery

    Java Training in Tambaram

    Java Training in Porur

    Java Training in Omr

    Java Training in Annanagar


    ReplyDelete
  8. This comment has been removed by the author.

    ReplyDelete
  9. This is an awesome post.Really very informative and creative contents. These concept is a good way to enhance the knowledge.I like it and help me to development very well.Thank you for this brief explanation and very nice information.Well, got a good knowledge.
    IELTS Coaching in chennai

    German Classes in Chennai

    GRE Coaching Classes in Chennai

    TOEFL Coaching in Chennai

    Spoken english classes in chennai | Communication training

    ReplyDelete
  10. Good job in presenting the correct content with the clear explanation. The content looks real with valid information. Good Work

    DevOps is currently a popular model currently organizations all over the world moving towards to it. Your post gave a clear idea about knowing the DevOps model and its importance.

    DevOps Training in Chennai

    DevOps Course in Chennai

    ReplyDelete
  11. Learn Amazon Web Services for excellent job opportunities from Infycle Technologies, the best AWS training center in Chennai. Infycle Technologies gives the most trustworthy AWS course in Chennai, with full hands-on practical training from professional trainers in the field. Along with that, the placement interviews will be arranged for the candidates, so that, they can meet the job interviews without missing them. To transform your career to the next level, call 7502633633 to Infycle Technologies and grab a free demo to know more
    Top AWS Course in Chennai | Infycle Technologies

    ReplyDelete
  12. It is very interesting! Really useful for me and thank you for this amazing blog.
    Woman Divorce Lawyers Near Me
    Fairfax Divorce Attorney

    ReplyDelete