private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
if (_IsHandlingException)
{
return;
}
_IsHandlingException = true;
// TODO: Add config option to allow users to turn off error reporting
// TODO: Post error report (disabled for now)
string msg = String.Empty;
msg += "\r\n";
msg += "APPLICATION EXCEPTION DETECTED: " + e.ToString() + "\r\n";
msg += "\r\n";
msg += "Exception: " + e.ExceptionObject.ToString() + "\r\n";
Exception ex = (Exception) e.ExceptionObject;
if (ex.InnerException != null)
{
msg += "InnerException: " + ex.InnerException.ToString() + "\r\n";
}
msg += "\r\n";
msg += "Application is terminating: " + e.IsTerminating.ToString() + "\r\n";
m_log.ErrorFormat("[APPLICATION]: {0}", msg);
if (m_saveCrashDumps)
{
// Log exception to disk
try
{
if (!Directory.Exists(m_crashDir))
{
Directory.CreateDirectory(m_crashDir);
}
string log = Util.GetUniqueFilename(ex.GetType() + ".txt");
using (StreamWriter m_crashLog = new StreamWriter(Path.Combine(m_crashDir, log)))
{
m_crashLog.WriteLine(msg);
}
File.Copy("OpenSim.ini", Path.Combine(m_crashDir, log + "_OpenSim.ini"), true);
}
catch (Exception e2)
{
m_log.ErrorFormat("[CRASH LOGGER CRASHED]: {0}", e2);
}
}
_IsHandlingException = false;
}
}