public static void WriteDebugException(bool bWriteError, string sSrc, Exception objErr)
{
#if DEBUG
bWriteError = true; // always write errors when debug build
#endif
if (bWriteError && objErr != null) {
StringBuilder sb = new StringBuilder();
sb.AppendLine("---------------- " + sSrc.ToUpperInvariant() + " - " + DateTime.Now.ToString() + " ----------------");
sb.AppendLine("[" + objErr.GetType().ToString() + "] " + objErr.Message);
if (objErr.StackTrace != null) {
sb.AppendLine(objErr.StackTrace);
}
if (objErr.InnerException != null) {
sb.AppendLine(objErr.InnerException.Message);
}
string filePath = HttpContext.Current.Server.MapPath("~/carrot_errors.txt");
Encoding encode = Encoding.Default;
lock (logLocker) {
using (FileStream fs = new FileStream(filePath, FileMode.Append, FileAccess.Write, FileShare.ReadWrite)) {
using (StreamWriter oWriter = new StreamWriter(fs, encode)) {
oWriter.Write(sb.ToString());
}
}
}
}
}