Page Nav

SHOW

Grid

GRID_STYLE

Hover Effects

TRUE

Pages

Latest Tech Updates

latest

How to Write a Log in .Net Application.

  In Application development environment we always require to track our application performance as well as error and bugs.To tracking bugs a...

 In Application development environment we always require to track our application performance as well as error and bugs.To tracking bugs and error we always write the log in temporary folder.So today we are going to discuss how to write the log in .Net application.Writing log is not save our time as well as helps us to track our application in proper manner

Today in this blog i will tell you how to write the log using C# programming Language.

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class WriteLogFile
    {
        public static bool WriteLog(string strFileName,string strMessage)
        {
            try
            {
FileStream objFilestream =new FileStream(string.Format("{0}\\{1}", Path.GetTempPath(), strFileName)
,FileMode.Append, FileAccess.Write);
StreamWriter objStreamWriter = new StreamWriter((Stream)objFilestream);
objStreamWriter.WriteLine(strMessage);
objStreamWriter.Close();
objFilestream.Close();
return true;
            }
            catch(Exception ex)
            {
                return false;
            }
        }
    }

Call the above WriteLog() method any app and pass parameter it will write the Log automatically.