LogToHtml 2.0.1

dotnet add package LogToHtml --version 2.0.1                
NuGet\Install-Package LogToHtml -Version 2.0.1                
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.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add LogToHtml --version 2.0.1                
#r "nuget: LogToHtml, 2.0.1"                
#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.1

// Install LogToHtml as a Cake Tool
#tool nuget:?package=LogToHtml&version=2.0.1                

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 Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 is compatible.  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.

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
2.0.1 426 1/9/2023
2.0.0 335 11/29/2022
1.0.4 312 12/1/2021
1.0.3 255 10/12/2021
1.0.2 254 9/29/2021
1.0.1 190 9/29/2021
1.0.0 164 9/28/2021

Added .NET 6 support and sealed specific internal classes.