I encountered an issue when trying to log the content into the .txt file.
Below is my code. It will keep hit the exception as the process happen too fast. Is there anyway to write a queue to wait or a locker to lock the current thread first?
DateTime time = DateTime.Now;
time = time.Minute > 30 ? time.Date.AddHours(time.Hour).AddMinutes(30) : time.Date.AddHours(time.Hour).AddMinutes(0);
var FilePath = "C:/temp/DebugLog/"+ webService + "/" + time.ToString("yyyyMMddHHmss") + "_Logs/";
if (!Directory.Exists(FilePath)) { Directory.CreateDirectory(FilePath); }
try
{
using (StreamWriter w = File.AppendText(FilePath + time.ToString("yyyyMMddHHmss") + ".txt"))
{
w.WriteLine(
Guid.NewGuid().ToString("N") + "; " + DateTime.Now.ToString("yyyyMMddHHmssms") + "; " +
webService + "; " + eventName + "; " + DateTime.Now.ToString() + "; " + transactionId + "; " + debuglog);
w.Close();
}
}
catch (Exception ex)
{
}
}