Best practices for logging user actions in production

Posted by anthonypliu on Programmers See other posts from Programmers or by anthonypliu
Published on 2012-10-09T00:05:02Z Indexed on 2012/10/09 3:50 UTC
Read the original article Hit count: 423

Filed under:
|
|

I was planning on logging a lot of different stuff in my production environment, things like when a user:

  • Logs In, Logs Off
  • Change Profile
  • Edit Account settings
  • Change password ... etc

Is this a good practice to do on a production enviornment? Also what is a good way to log all this. I am currently using the following code block to log to:

public void LogMessageToFile(string msg)
        {

            System.IO.StreamWriter sw = System.IO.File.AppendText(
                GetTempPath() + @"MyLogFile.txt");
            try
            {
                string logLine = System.String.Format(
                    "{0:G}: {1}.", System.DateTime.Now, msg);
                sw.WriteLine(logLine);
            }
            finally
            {
                sw.Close();
            }
        }

Will this be ok for production? My application is very new so im not expecting millions of users right away or anything, looking for the best practices to keeping track of actions on a website or if its even best practice to.

© Programmers or respective owner

Related posts about c#

Related posts about ASP.NET