Hi guys
I am writing an application in c#
I want to create a dynamic log file which would contain all the errors or exceptions occurred during execution of the Component.

Log file simply has to append all the errors or exceptions generated with error details and time and date.

Any Ideas?

Hi,

Few thoughts;

1) Create a separate class and function which contains the log file generation and appending the text using FileStream and StreamWriter Classes.
2) Derive the object for the class
3) Call the the function and pass the exception messages

Some sample code;

public void writelog(string msg)
{
FileStream fs = new FileStream(log_FileName, FileMode.CreateNew, FileAccess.ReadWrite);
StreamWriter sw = new StreamWriter(fs);
sw.WriteLine(msg);
sw.Close();
fs.Close();
}
catch
{
obj.writelog(ex.Message)
}

The above code is not complete. Its sample only.

Good luck.

Edited 6 Years Ago by MeSampath: n/a

Hi,

Few thoughts;

1) Create a separate class and function which contains the log file generation and appending the text using FileStream and StreamWriter Classes.
2) Derive the object for the class
3) Call the the function and pass the exception messages

Some sample code;

public void writelog(string msg)
{
FileStream fs = new FileStream(log_FileName, FileMode.CreateNew, FileAccess.ReadWrite);
StreamWriter sw = new StreamWriter(fs);
sw.WriteLine(msg);
sw.Close();
fs.Close();
}
catch
{
obj.writelog(ex.Message)
}

The above code is not complete. Its sample only.

Good luck.

Thanks for quick reply...
I had to add few more things but its working now.

This question has already been answered. Start a new discussion instead.