Debugging

Energy.Core.Bug is the library’s internal debugging and exception logging helper. It is used by many other classes to report errors, trace execution, and log diagnostic information.

Writing messages

Energy.Core.Bug.Write("Application started");
Energy.Core.Bug.Write("E001", "Error description");
Energy.Core.Bug.Write("E002", () => "Lazy message");

Catching exceptions

try
{
    int.Parse("not a number");
}
catch (Exception exception)
{
    Energy.Core.Bug.Catch(exception);
    Energy.Core.Bug.Catch("E003", exception);
}

Exception messages

string message = Energy.Core.Bug.ExceptionMessage(exception);
string messageTrace = Energy.Core.Bug.ExceptionMessage(exception, true);

Suppression

Energy.Core.Bug.Suppress("E001");
Energy.Core.Bug.Suppress("E0*", false);

if (Energy.Core.Bug.IsSuppressed("E001"))
{
    // ...
}

Debug output

string output = Energy.Core.Bug.FormatDebugOutput("E001", "Message");
string output2 = Energy.Core.Bug.FormatDebugOutput("Message");

Entry

Energy.Core.Bug.Entry is a simple code/message pair.

Logger

Set a logger to receive bug messages.

Energy.Core.Bug.Logger = Energy.Core.Log.Default;

Summary

Method Description
Write(string) Write a debug message.
Write(string, string) Write a coded message.
Write(string, Func<string>) Write a lazy message.
Write(Exception) Write an exception.
Catch(Exception) Catch and log an exception.
ExceptionMessage(Exception) Format exception message.
Suppress(string) Suppress a message code.
IsSuppressed(string) Check if a code is suppressed.
Clear() Clear suppression list.