dotnetspider.com
Login Login    Register      

TutorialsForumCareer DevelopmentResourcesReviewsJobsInterviewCommunitiesProjectsTraining

Subscribe to Subscribers
Talk to Webmaster
Tony John

Facebook
Google+
Twitter
LinkedIn
Online MembersPrasad kulkarni
Akshata
More...
Join our online Google+ community for Bloggers, Content Writers and Webmasters




Resources » Code Snippets » File Operations

How to maintain the log file to track application performance using C#?


Posted Date:     Category: File Operations    
Author: Member Level: Gold    Points: 20


There is a sample code to check performance of the application by calculating execution time which is required for each and every methods in application. Code has been developed in C# whereas application is windows based.



 


How to maintain the log file to track application performance?
Description- Create a class library and put this code snippet in to it.
Calculate start time at the beginning of the method and endtime at the end of the method for which you are calculating the execution performance.
It can used to rectify if refactoring needs to be done for any method.
To call this method, you have to create an object of this class library and call.


class MethodLog
{
//This method is used for calculating method time in each class.
public void GetMethodLog(string clsname , string methodname , int lineno , string description , string methodstarttime , string methodendtime)
{
// get the base directory
string baseDir = AppDomain.CurrentDomain.BaseDirectory + AppDomain.CurrentDomain.RelativeSearchPath;

// search the file below the current directory
string retFilePath = baseDir + "//" + "LogFile.txt";

// Create a writer and open the file:
StreamWriter log;

if (!File.Exists(retFilePath))
{
log = new StreamWriter(retFilePath);
}
else
{
log = File.AppendText(retFilePath);
}

string strclsname = "Class Name : " + clsname ;
string strmethodname = "Method Name : " + methodname ;
string strlineno = "Line Number : " + lineno ;
string strdescription = "Method Description :" + description ;
string strmethodstarttime = "Method Start Time :" + methodstarttime ;
string strmethodendtime = "Method End Time :" + methodendtime ;
string eol = "^^---------------------------------------------------------^^";

// Write log entries to the file:
log.WriteLine(strclsname);
log.WriteLine(strmethodname);
log.WriteLine(strlineno);
log.WriteLine(strdescription);
log.WriteLine(strmethodstarttime);
log.WriteLine(strmethodendtime);
log.WriteLine(eol);

// Close the stream:
log.Close();
}

}





Did you like this resource? Share it with your friends and show your love!


Responses to "How to maintain the log file to track application performance using C#?"

No responses found. Be the first to respond...

Feedbacks      

Post Comment:




  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)



    Type the numbers and letters shown on the left.


    Next Resource: Reading and writing data using StreamReader and StreamWriter classes
    Previous Resource: How to capture all the comments from class files (.cs) using C#?
    Return to Resources
    Post New Resource
    Category: File Operations


    Post resources and earn money!
     
    More Resources
    Popular Tags   Tag posting guidelines   Search Tags  
    (No tags found.)



    Follow us on Twitter: https://twitter.com/dotnetspider

    Active Members
    TodayLast 7 Daysmore...

    Awards & Gifts
    Email subscription
  • .NET Jobs
  • .NET Articles
  • .NET Forums
  • Articles Rss Feeds
    Forum Rss Feeds


    About Us    Contact Us    Copyright    Privacy Policy    Terms Of Use    Revenue Sharing sites   Advertise   Talk to Tony John
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
    2005 - 2012 All Rights Reserved.
    .NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
    Articles, tutorials and all other content offered here is for educational purpose only.
    We are not associated with Microsoft or its partners.