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.

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.

kindly mark this thread as solved if your problem is solved..........

Take a look at log4net. it's easy to use and works very well.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.