Log message with StreamWriter
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
class Utility
{
private static bool _debugLogging = false;
internal static void LogMessage(string message)
{
if (_debugLogging == false)
return;
DateTime dt = DateTime.Now;
String filePath = Path.Combine(Path.GetTempPath(), "TeamDeploy" + dt.ToString("yyyyMMdd") + ".log");
if (!File.Exists(filePath))
{
FileStream fs = File.Create(filePath);
fs.Close();
}
try
{
StreamWriter sw = File.AppendText(filePath);
sw.WriteLine(dt.ToString("hh:mm:ss") + "|" + message);
sw.Flush();
sw.Close();
}
catch (Exception)
{
throw;
}
}
}
Related examples in the same category