Cybercrux

Everything is achievable through technology

C# Log Debugging

Independent Log creation code 

<add key="logFilePath" value="D:\logFile.txt"/>

public static void function in util.cs

public static void writeToLogFile(string logMessage)
{
string strLogMessage = string.Empty;
string strLogFile = System.Configuration.ConfigurationManager.AppSettings[“logFilePath”].ToString();
StreamWriter swLog;

strLogMessage = string.Format(“{0}: {1}”, DateTime.Now, logMessage);

if (!File.Exists(strLogFile))
{
swLog = new StreamWriter(strLogFile);
}
else
{
swLog = File.AppendText(strLogFile);
}

swLog.WriteLine(strLogMessage);
swLog.WriteLine();

swLog.Close();

}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s