One of the things I’ve learned making games, is that if you’re going to release your game to people you NEED to have some sort of error logging. Otherwise, everyone will tell you that your game crashes and you’ll have no idea why. Sure you tested the game a ton, but there are bugs you probably weren’t able to find. It could be a system specific file path problem, it could be a parsing issue to do with the users region, who knows.
How To Do It
In C# logging errors is pretty damn easy, all you really need is a global exception handler. You can set one up like this:
[sourcecode language=”csharp”]
static void Main()
{
AppDomain.CurrentDomain.UnhandledException += ExceptionTrapper;
main = new DuckGame.Main();
main.Run();
}
static void ExceptionTrapper(object sender, UnhandledExceptionEventArgs e)
{
string error = e.ExceptionObject.ToString();
System.IO.StreamWriter file = new System.IO.StreamWriter("log.txt", true);
file.WriteLine(error + "\n");
file.Close();
}
[/sourcecode]
Now whenever something goes wrong, your game will spit out a log of the error next to it!