How to create a custom error log in C#

How to create a custom error log in C#

This is the easiest way to track your errors in your system. Save the details in a text file, here’s how to do it.

Add a public class in your project so that it would be globally used.

public void ErrLogs(string log, string path)
string sLogFormat = DateTime.Now.ToShortDateString().ToString() + ” ” + DateTime.Now.ToLongTimeString().ToString() + ” ==> “;
string spath = path + DateTime.Now.ToShortDateString().ToString() + “.txt”;

FileStream fs = new FileStream(spath, FileMode.OpenOrCreate, FileAccess.ReadWrite);
StreamWriter m_streamWriter = new StreamWriter(fs);
m_streamWriter.BaseStream.Seek(0, SeekOrigin.End);
string value = sLogFormat + log;

This is what it looks like in your text file.

kishor bhatta

Hello! I am Kishor Bhatta, a Professional Blogger, and Digital Marketing Strategist. I am the founder of InspiringWorm.

Leave a Comment