ConsoleDebugger is a lightweight utility for console applications, providing robust logging and debug message management. It is ideal for applications with multiple asynchronous methods, background processes, or network operations. As of v1.0.8, advanced features such as audible beeps and float tracking are now available as separate extension packages, reducing the core package size and dependencies for users who only need basic logging.
To use ConsoleDebugger in your C# console application:
- Install the core ConsoleDebugger package via NuGet:
dotnet add package ConsoleDebugger --version 1.0.8
- Add the following using directive in your C# files:
using ConsoleDebugger.ConsoleDebugger;
Or, for a more functional approach:
using static ConsoleDebugger.ConsoleDebugger;
-
Audible Beeps:
InstallConsoleDebugger.Beeps
for beep/tone support:dotnet add package ConsoleDebugger.Beeps --version 1.0.8
using ConsoleDebugger.Beeps;
-
Float Tracking:
InstallConsoleDebugger.FloatTracker
for auditory float tracking:dotnet add package ConsoleDebugger.FloatTracker --version 1.0.8
using ConsoleDebugger.FloatTracker;
Log debug messages with different colors and message types:
Result result = SomeNetworkFunction(); // example function
ConsoleDebugger.DebugMessage("We started the network function.");
if(result == Good){
ConsoleDebugger.DebugMessage($"Here's the result {result.ToString()}", ConsoleColor.Blue);
} else {
ConsoleDebugger.DebugMessage($"Critical error occurred: {result.Message}", MessageType.Critical);
}
You can define and control logging categories:
var netCategory = new LoggingCategory("Network");
ConsoleDebugger.AddLoggingCategory(netCategory);
ConsoleDebugger.DebugMessage("Network started", netCategory);
You can also control which logging categories are shown in the console output. By default, all categories are considered enabled. Use ActivateLoggingCategory(category)
to enable console output for a category, or DeactivateLoggingCategory(category)
to suppress it so the category no longer outputs to the console.
Note: Logging categories are always included in the file log if file logging is enabled, regardless of their console output status.
You can log messages to a file in either .txt
or .csv
format. By default, logs include the message, but you can configure additional options such as including timestamps, logging categories, and message types. The output format and included fields are controlled via the LoggingConfiguration
class.
- .txt format: Plain text log entries, optionally with timestamp, category, and message type.
- .csv format: Comma-separated values, suitable for importing into spreadsheets or analysis tools. Each field (timestamp, category, type, message) appears as a column if enabled.
Enable or disable file logging:
ConsoleDebugger.StartLogging();
// ... your code ...
ConsoleDebugger.StopLogging();
Configure logging style and options via the LoggingConfiguration
class, for example:
var config = new LoggingConfiguration {
IncludeTimestamp = true,
IncludeCategory = true,
IncludeMessageType = true,
LogFormat = LogFormat.Csv // or LogFormat.Txt
};
ConsoleDebugger.SetLoggingConfiguration(config);
To use beeps, ensure you have installed the ConsoleDebugger.Beeps
package and initialized beeps:
ConsoleDebugger.InitializeBeeps();
ConsoleDebugger.DebugBeep(TonePitch.Do, ToneLength.Short);
ConsoleDebugger.DebugBeep(TonePitch.Re, ToneLength.Short);
To use float tracking, ensure you have installed the ConsoleDebugger.FloatTracker
package and initialized float tracking:
ConsoleDebugger.InitializeFloatTracking();
float valueToTrack = 0.0f;
var synthesizer = ConsoleDebugger.StartTrackingFloat(ref valueToTrack, 0.0f, 100.0f);
As valueToTrack
changes, an auditory tone will represent its value within the specified range.
DebugMessage(string message, LoggingCategory category = default)
DebugMessage(string message, ConsoleColor color, LoggingCategory category = default)
DebugMessage(string message, MessageType type, LoggingCategory category = default)
StartLogging()
,StopLogging()
- Logging category management:
AddLoggingCategory
,RemoveLoggingCategory
,ActivateLoggingCategory
,DeactivateLoggingCategory
,LoggingCategoryActive
DebugBeep(TonePitch pitch, ToneLength duration)
InitializeBeeps()
StartTrackingFloat(ref float target, float minrange, float maxrange) : FloatSynthesizer
InitializeFloatTracking()
This project is licensed under the MIT License. See the LICENSE file for details.