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 not only saves our time as well as helps us to track our application in proper manner.
So 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;
- namespace BackToBasicProj
- {
- 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;
- }
- }
- }
- }

Akshay PPosted May 28, 2021, 7:44 AM
I have a large of 10 lakhs records while exporting from one excel to another excel its taking much time,please help to increase the performance
bishoe nbPosted Apr 8, 2020, 2:23 PM
Thank you..
Hưng TrầnPosted Oct 4, 2019, 2:50 AM
Why can't the file be found?
SubashPosted Sep 15, 2016, 7:23 AM
Nice one
Bhuvan PandeyPosted Aug 17, 2016, 5:37 AM
Good.