MetaLogger 1.0.2
dotnet add package MetaLogger --version 1.0.2
NuGet\Install-Package MetaLogger -Version 1.0.2
<PackageReference Include="MetaLogger" Version="1.0.2" />
<PackageVersion Include="MetaLogger" Version="1.0.2" />
<PackageReference Include="MetaLogger" />
paket add MetaLogger --version 1.0.2
#r "nuget: MetaLogger, 1.0.2"
#:package MetaLogger@1.0.2
#addin nuget:?package=MetaLogger&version=1.0.2
#tool nuget:?package=MetaLogger&version=1.0.2
MetaLogger
MetaLogger is a lightweight C# logging library that supports both static and instance-based logging. It includes features such as debug mode, custom log directories, file suffixes, and caller information. The instance-based logger also allows you to add custom prefixes or suffixes to every log message.
Features
Static Logger (MetaLogger)
- Quick access via static methods
- Supports logging information, warnings, errors, debug messages, and crash logs
- Optionally includes caller information in log messages
- Customizable log directory and file name suffix
Instance Logger (InstanceLogger)
- Allows multiple logger instances with different configurations
- Supports custom message prefixes and suffixes
- Same logging levels as the static logger (information, warning, error, debug, and crash)
- Customizable log directory and file name suffix
Installation
Install via NuGet
You can install MetaLogger from NuGet:
Install-Package MetaLogger
Or via the .NET CLI:
dotnet add package MetaLogger
Clone the Repository (Alternative Installation)
git clone https://github.com/Jacobwasbeast/MetaLogger.git
Include in Your Project
Add the MetaLogger project or its source files to your solution. Then add a reference from your main project to the MetaLogger project.
Basic Setup
Static Logger
The static logger is available via the MetaLogger
class. It is ideal for quick logging without needing to create an instance.
Example Usage
using MetaLogger;
using System;
class Program
{
static void Main(string[] args)
{
// Set the log directory (optional)
MetaLogger.SetLogDirectory("my_logs");
// Optionally, enable debug mode and set a log file suffix.
MetaLogger.EnableDebugMode(true);
MetaLogger.SetLogFileSuffix("v1");
// Log some messages.
MetaLogger.LogInformation("Application started at {0}", DateTime.Now);
MetaLogger.LogWarning("Low disk space on drive {0}", "C:");
try
{
// Simulate an error.
throw new Exception("Something went wrong!");
}
catch (Exception ex)
{
MetaLogger.LogError(ex, "An exception occurred while processing data.");
}
// Log a debug message.
MetaLogger.LogDebug("This is a debug message.");
}
}
Instance Logger
The instance-based logger (InstanceLogger
) allows you to have multiple loggers with different configurations. It also lets you set a custom message prefix and suffix for every log entry.
Example Usage
using MetaLogger;
using System;
class Program
{
static void Main(string[] args)
{
// Create a new InstanceLogger
InstanceLogger logger = new InstanceLogger();
// Configure the logger
logger.SetLogDirectory("instance_logs");
logger.SetLogFileSuffix("build42");
logger.EnableDebugMode(true);
logger.SetMessagePrefix("[MyApp] ");
logger.SetMessageSuffix(" ~EndLog");
// Log some messages using the instance logger
logger.LogInformation("Instance logger initialized at {0}", DateTime.Now);
logger.LogWarning("This is a warning message.");
try
{
// Simulate an error
throw new InvalidOperationException("Invalid operation!");
}
catch (Exception ex)
{
logger.LogError(ex, "Error occurred while executing operation.");
}
// Log a debug message.
logger.LogDebug("This is a debug message from the instance logger.");
}
}
Configuration Options
Both loggers offer similar configuration settings:
Log Directory:
UseSetLogDirectory(string directory)
to specify where logs should be stored.File Suffix:
UseSetLogFileSuffix(string suffix)
to add a suffix to the log file names (useful for versioning or timestamps).Debug Mode:
Enable or disable debug mode usingEnableDebugMode(bool enable)
. When enabled, debug messages are written to both the log file and the console.Caller Information:
Toggle the inclusion of caller information (e.g., file name, line number) in log messages usingSetIncludeCallerInfo(bool include)
.Custom Message Prefix/Suffix (InstanceLogger only):
Customize every log message by adding a prefix usingSetMessagePrefix(string prefix)
and a suffix usingSetMessageSuffix(string suffix)
.
Building and Running
Build the Project:
Use your favorite IDE (such as Visual Studio) or the .NET CLI:dotnet build
Run the Application:
For example, using the .NET CLI:dotnet run --project YourProjectName
License
This project is licensed under the MIT License.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.