i am a beginner..
I developed an application in which server n clients communicate with each other,
i have to log the conversation between the client and server in a text file.
How to do that? Plz help me..
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
vijayPosted Jul 7, 2009, 7:20 AM
ur response s very easy to understand and so useful.
Niradhip ChakrabortyPosted Jul 7, 2009, 7:16 AM
Create a textfile inside your application say "Log.txt";
System.IO.StreamWriter objWriter;//Declare this as public.
string LOG_FILE_NAME; //Declare this as public.
protected void Page_Load(object sender, EventArgs e)
{
LOG_FILE_NAME = Server.MapPath("Log.txt");
}
Now you will be knowing what will be the conversation between server and client. Put this in a string and call it in the following function inside the proper event handler.
string strMessage ="";//assign the conversation here
WriteLogMessage (strMessage);
public void WriteLogMessage(string strMessage)
{
try
{
if (System.IO.File.Exists(LOG_FILE_NAME) == true)
{
objWriter = System.IO.File.AppendText(LOG_FILE_NAME);
}
else
{
objWriter = System.IO.File.CreateText(LOG_FILE_NAME);
}
objWriter.Write(strMessage + Environment.NewLine);
}
catch (Exception ex)
{
}
finally
{
objWriter.Flush();
objWriter.Close();
}
}