Bytehide.Logger
1.0.0
dotnet add package Bytehide.Logger --version 1.0.0
NuGet\Install-Package Bytehide.Logger -Version 1.0.0
<PackageReference Include="Bytehide.Logger" Version="1.0.0" />
paket add Bytehide.Logger --version 1.0.0
#r "nuget: Bytehide.Logger, 1.0.0"
// Install Bytehide.Logger as a Cake Addin #addin nuget:?package=Bytehide.Logger&version=1.0.0 // Install Bytehide.Logger as a Cake Tool #tool nuget:?package=Bytehide.Logger&version=1.0.0
__
/ / ____ ____ _____ ____ _____
/ / / __ \/ __ `/ __ `/ _ \/ ___/
/ /___/ /_/ / /_/ / /_/ / __/ /
/_____/\____/\__, /\__, /\___/_/
/____//____/
ByteHide.Logger SDK
ByteHide.Logger is a flexible and powerful logging library for .NET applications, providing advanced features such as file rotation, data masking, duplicate log suppression, user identification, and metadata enrichment to ensure robust logging and analysis capabilities.
Installation
The ByteHide.Logger SDK can be added to your .NET project via NuGet: Once installed, you can begin integrating it into your project to take advantage of its wide array of features.
Features
- Log Persistence: Store logs in a file and optionally rotate logs based on time intervals or file size.
- Console Logging: Output logs to the console for immediate feedback during development.
- Duplicate Log Suppression: Automatically suppress duplicate logs within a configurable time window.
- Data Masking: Protect sensitive information like passwords or tokens by masking them in the logs.
- User Identification: Track actions performed by specific users by globally identifying them in the logs.
- Metadata Enrichment: Add contextual information (e.g., app version, environment) to enrich your logs.
- Log Level Control: Configure the minimum logging level (e.g., Info, Warn, Error) to capture relevant messages.
Usage
Once configured, you can initialize and use ByteHide.Logger in your application.
Initialization
- Initialize the logger with a set of custom
LogSettings
. - Identify users globally if needed.
- Log messages at different levels (Info, Warning, Error).
- Add metadata to logs, and handle exceptions with additional context.
Example
using Bytehide.Logger.Common.Models;
using Bytehide.Logger.Common.Models.Users;
using Bytehide.Logger.Core;
Log.Initialize(new LogSettings
{
Persist = true,
FilePath = "logs/app-logs.txt",
RollingInterval = RollingInterval.Day,
FileSizeLimitBytes = 10 * 1024 * 1024,
ConsoleEnabled = true,
MinimumLevel = LogLevel.Info,
MaskSensitiveData = new[] { "password", "token" },
DuplicateSuppressionWindow = TimeSpan.FromSeconds(5),
MaxFileSize = 5 * 1024 * 1024
});
Log.SetProjectToken("your-project-token");
Log.Info("Application started.");
Log.Identify(new AuthUser { Id = "12345", Email = "user@example.com" });
Log.Warn("User experienced a delay in the database query.");
try
{
throw new Exception("Database connection failed.");
}
catch (Exception ex)
{
Log.Error("An error occurred while connecting to the database.", ex);
}
Log.Disable();
Log.Warn("This log won't be recorded as logging is disabled.");
Log.Enable();
Log.Info("Logging re-enabled.");
Advanced Features
- Global Properties: You can enrich logs with global properties that are included with every log entry.
Log.AddMetaContext("AppVersion", "1.2.3");
Log.AddMetaContext("Environment", "Production");
- Correlation IDs: Track operations using correlation IDs for consistent logging across an entire process.
Log.WithCorrelationId("operation-123").Info("Payment process started.");
- Reset Configuration: Easily reset logger settings to defaults when needed.
Log.Reset();
Usage with Global Environment Variables
You can set global environment variables to configure the logger without explicitly initializing it in your application.
ByteHide.Logger.Environment
ByteHide.Logger.Token
Usage with Local Environment Variables
You can also use local environment variables. You can use an app.config file.
Your app.config file should look like this:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="ByteHide.Logger.Environment" value="development"/>
<add key="ByteHide.Logger.Token" value="e34762f8-8ad6-0000-0000-000000000000"/>
</appSettings>
</configuration>
But if you want to override the environment variables, you can still do it:
Log.SetProjectToken("your-project-token");
Log.AddMetaContext("Environment", "Production");
License
ByteHide.Logger is licensed under 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. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. 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.0
- ICSharpCode.Decompiler (>= 8.2.0.7535)
- System.Configuration.ConfigurationManager (>= 8.0.0)
- System.Text.Json (>= 8.0.4)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.0 | 37 | 11/18/2024 |