Log Visitors details using c#

Recently I have developed one application for the automation. It was web application.
I wanted to track the visitor visited or used my application and then store all the visitors information in “*.csv” file.
For that purpose I have used below code :

string strVisitorLogLocation=”C://VisitorsLog.csv” ;
string strIpAddress =Request.ServerVariables[“HTTP_X_FORWARDED_FOR“];
if (strIpAddress == null)
strIpAddress = Request.ServerVariables[“REMOTE_ADDR”];

string hostName = Dns.GetHostByAddress(strIpAddress).HostName;
StreamWriter wrtr = new StreamWriter(strVisitorLogLocation, true);
wrtr.WriteLine(DateTime.Now.ToString() + “,” + strIpAddress + “,” + hostName + “,” + Request.Url.ToString());

catch (Exception ex)

you can use this snipet of the code to get the visitor details like hostname,ipaddress of visitor machine and which all pages he is visited on you application. Thanks!!


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s