Using this AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(Handle); from Hybrids source thought.
What I have done is:
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ConquerServerProject.FileHandler;
namespace ConquerServerProject.Core
{
public class ExceptionHandler
{
public static bool GlobalUnhandledError = false;
FileLog ExceptionLog;
public ExceptionHandler()
{
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(Handle);
#if EXCEPTION_LOG
ExceptionLog = new FileLog("exceptionlog.txt");
ExceptionLog.Open();
#endif
}
private void Handle(object sender, UnhandledExceptionEventArgs e)
{
FileLog GlobalExceptionLog = new FileLog("globalexceptions.txt");
GlobalExceptionLog.Open();
GlobalExceptionLog.Write("[Global Exception - " + DateTime.Now + "]");
GlobalExceptionLog.Write("Exception:\n" + e.ToString());
GlobalExceptionLog.End();
GlobalUnhandledError = true;
}
public void Handle(Exception exception)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(exception.ToString());
Console.ResetColor();
#if EXCEPTION_LOG
ExceptionLog.Write("[Exception - " + DateTime.Now + "]");
ExceptionLog.Write("Exception:\n" + exception.ToString());
if (exception.InnerException != null)
{
ExceptionLog.Write("\nInner Exception:\n" + exception.InnerException.ToString());
}
#endif
}
}
}






