LogToHtml 2.0.0
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package LogToHtml --version 2.0.0
NuGet\Install-Package LogToHtml -Version 2.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="LogToHtml" Version="2.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add LogToHtml --version 2.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: LogToHtml, 2.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install LogToHtml as a Cake Addin #addin nuget:?package=LogToHtml&version=2.0.0 // Install LogToHtml as a Cake Tool #tool nuget:?package=LogToHtml&version=2.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
LogToHtml
A small library to write logs to a .html file. The HTML file's structure is based on an embedded .cshtml file.
Usage
Write a log
using LogToHtml;
using System.Reflection;
namespace Example
{
internal class Program
{
#region Configure options for each individual log entry
public static Log.Options Options = new()
{
// Name of the project that you're currently logging from.
// If you have a solution with multiple projects,
// you would change this value for each different project.
Project = $"{Assembly.GetCallingAssembly().GetName().Name}",
// Indicate if you just want to write to the HTML file or also output results on the console.
LogToConsole = true
};
#endregion
static void Main(string[] args)
{
#region Configure global options
// These are applied across all projects in a solution.
// [Required]
// A List of projects that the logger is used for.
// If you only use the logger in a single project assign the same value here as you did in 'Options.Project'
List<string> projects = new()
{
$"{Assembly.GetCallingAssembly().GetName().Name}"
};
// [Optional]
// The path where the log file is located.
string logpath = Path.Combine(Environment.CurrentDirectory, "logs", "log.html");
// [Optional]
// Set the maximum size of a log file (example has a max size of 1 MB).
int maxSize = 1000000;
// [Optional]
// Set what timezone the library uses.
TimeZoneInfo timezone = TimeZoneInfo.FindSystemTimeZoneById("Central America Standard Time");
// [Optional]
// Change what colors the library writes to the console based on LogLevel.
Configuration.Colors colors = new()
{
Info = "0, 255, 255",
Warn = "0,95,95",
Error = "#5f0000",
Critical = "#d75f00"
};
// [Optional]
// Change what get's written to the console.
Configuration.ConsoleConfig consoleConfig = new()
{
// If console displays LogLevel in color
Color = true,
Date = true,
FileName = true,
LineNumber = false,
LogLevel = true,
MethodName = false,
ProjectName = true
};
// You only need to set this once in your entire solution.
_ = new Configuration(projects, logpath, maxSize, timezone, colors, consoleConfig);
#endregion
// And now you can start logging
Log.Info(Options, $"This is a test message");
}
}
}
Retrieve written logs
using LogToHtml.Models;
// Get all logs
GetLogs allLogs = Log.GetLogs();
// Get all logs with the info LogLevel
List<LogData> infoLogs = Log.GetInfoLogs();
// Get all logs with the warn LogLevel
List<LogData> warnLogs = Log.GetWarnLogs();
// Get all logs with the error LogLevel
List<LogData> errorLogs = Log.GetErrorLogs();
// Get all logs with the critical LogLevel
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net5.0
- AngleSharp (>= 0.17.1)
- HtmlAgilityPack (>= 1.11.46)
- RazorLight (>= 2.3.0)
- Spectre.Console (>= 0.45.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Improved reliability, accessibility (log file) and added a whole bunch of configuration options.