MelonLoader

MelonLoader

242 Downloads

Add MelonLogger.Error overloads that also log a provided exception in a uniform way

zeobviouslyfakeacc opened this issue ยท 0 comments

commented

At the moment, whenever mod authors have to log some kind of an exception, they either use 2 calls to MelonLogger.Error, or they manually concatenate the message they want to log and the exception, possibly including a new line.

As a quality-of-life improvement, I propose adding an overload MelonLogger.Error(string txt, Exception ex), which handles this somewhat common task in a uniform way. It would first print the message txt, then include a newline character, and then print the exception message as well as its stack trace on the following lines.

This might be a source-incompatible (but binary-compatible) change due to the existence of the overload MelonLogger.Error(string txt, params object[] args):
Error("foo", new Exception()) used to resolve to the varargs overload, but would now resolve to the exception-printing overload.

Perhaps, even though it may be a bit uglier, MelonLogger.Error(Exception ex, string txt) would be the better argument order.
[Ugly and perhaps a bit confusing, since the message gets logged first, followed by the exception. Not sure what's best here.]
This would also allow adding MelonLogger.Error(Exception ex, string txt, params object[] args) as an analog to MelonLogger.Error(string txt, params object[] args).