I am trying to create a logfile for my project,whenever an err occurs,i want to store that info in my logfile,with a prefix of err
while reading the file,i want to check for this err prefix,and change that message color to red,only the err msg should come in red while others in blue.......
I have no idead to do this,please help,i am new to this.........
Thnks

This is the code i wrote for writing:

    public  void Writer()
    {
        try
        {
            // Specify file, instructions, and privelegdes
            FileStream objFileStrm = new FileStream(@"d:\log\testlog.txt", FileMode.Append , FileAccess.ReadWrite);

            // Create a new stream to write to the file
            StreamWriter objStrmWrite = new StreamWriter(objFileStrm);
            objStrmWrite.WriteLine(DateTime.Now);

            objStrmWrite.WriteLine("Writing to file....");

            // Close StreamWriter
            objStrmWrite.Close();

            // Close file
            objFileStrm.Close();

        }
        catch (Exception ex)
        {
            string strErr;
            strErr="err "+ ex.Message;
        }
    }

This i wrote for reading:

    public void Reader()
    {
        try
        {

            // Specify file, instructions, and privelegdes
            FileStream objFileStrm = new FileStream(@"d:\log\testlog.txt", FileMode.Open , FileAccess.Read);

            // Create a new stream to read from a file
            StreamReader objStrmRead = new StreamReader(objFileStrm);

            // Read contents of file into a string
            strData = objStrmRead.ReadToEnd();
            //txtLog.Text = strData;

            // Close StreamReader
            objStrmRead.Close();

            // Close file
            objFileStrm.Close();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }

eg for log.txt

Writing to the file
err not completed successfully
Writing to the file

if this is the data i have in my logfile.txt,and while reading i want to change color for err not completed successfully,and the color for the
remaining text should not be changed,how do i achieve this,plz help....
thnks

I assume you have a Visual Studio IDE. Use it's Help menu, select Search and type String members. You have here all the methods of String to get what you want to do like (SubString etc.)
Do the same for the Console class. Look here for the method ForeGroundColor and see the example given. Succes!

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.