I am very new to asp.net but have done asp and vb for a while. I am having to edit an existing .net app and want to add some logging. I added this into the .vb page and creates the file and does the logging.
What would be the best way to get the server variables Referrer and Querystring. I am really needed to log the query string.
I am looking around google and have not found anything yet.
Also, would this be the most efficient way to create the txt file and write to it?
What would be the best way to get the server variables Referrer and Querystring. I am really needed to log the query string.
I am looking around google and have not found anything yet.
Also, would this be the most efficient way to create the txt file and write to it?
Code:
'Open a file for writing
Dim Test_log_FILENAME As String = Server.MapPath("login_Log_" & DateTime.Now.ToString("yyyyMMdd") & ".txt")
'Get a StreamReader class that can be used to read the file
Dim objStreamWriter As StreamWriter
objStreamWriter = File.AppendText(Apollo_log_FILENAME)
Dim varQueryString As String
Dim varIPAddress As String
Dim varReferrer As String
varQueryString = ""
varIPAddress = Request.UserHostAddress
varReferrer = ""
objStreamWriter.WriteLine(DateTime.Now.ToString() & ": " & "-------------------")
objStreamWriter.WriteLine(DateTime.Now.ToString() & ": " & "Query String: " & varQueryString)
objStreamWriter.WriteLine(DateTime.Now.ToString() & ": " & "IP Address: " & varIPAddress)
objStreamWriter.WriteLine(DateTime.Now.ToString() & ": " & "Referrer: " & varReferrer)
objStreamWriter.WriteLine(DateTime.Now.ToString() & ": " & "-------------------")
'Close the stream
objStreamWriter.Close()