G4.Abstraction.Logging 2026.11.25.27

dotnet add package G4.Abstraction.Logging --version 2026.11.25.27
                    
NuGet\Install-Package G4.Abstraction.Logging -Version 2026.11.25.27
                    
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="G4.Abstraction.Logging" Version="2026.11.25.27" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="G4.Abstraction.Logging" Version="2026.11.25.27" />
                    
Directory.Packages.props
<PackageReference Include="G4.Abstraction.Logging" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add G4.Abstraction.Logging --version 2026.11.25.27
                    
#r "nuget: G4.Abstraction.Logging, 2026.11.25.27"
                    
#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.
#:package G4.Abstraction.Logging@2026.11.25.27
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=G4.Abstraction.Logging&version=2026.11.25.27
                    
Install as a Cake Addin
#tool nuget:?package=G4.Abstraction.Logging&version=2026.11.25.27
                    
Install as a Cake Tool

G4.Abstraction.Logging

G4.Abstraction.Logging is a small structured logger for G4™ applications. It implements Microsoft.Extensions.Logging.ILogger, writes each entry to a daily log file through a .NET trace listener, and raises events before and after each entry is created. It targets net10.0 and is marked as unsupported in browser environments.

Installation

dotnet add package G4.Abstraction.Logging

What it gives you

Type What it does Source
G4Logger The logger. Builds an entry, formats it, writes it to the trace listener, and raises events. G4Logger.cs:26
G4LoggerSettings The settings: event id, log levels, and the nested G4LoggerSettingsModel with console, debug, output directory and entry type. G4LoggerSettings.cs
G4LoggerProvider An ILoggerProvider that creates one G4Logger per category name and follows settings changes. G4LoggerProvider.cs:42
AddG4Logger Extension methods that register the provider on an ILoggingBuilder. G4LoggerExtensions.cs:23, 34
FindLogger<T> Extension method that looks inside a composite ILogger for an inner logger of type T. G4LoggerExtensions.cs:70
G4Logger.Instance A shared logger with the category G4.Api, built from appsettings.json. G4Logger.cs:32

Use the logger

1. Create a logger

The second argument is a function, so the logger can read fresh settings later.

using G4.Abstraction.Logging;

using Microsoft.Extensions.Logging;

var settings = new G4LoggerSettings
{
    G4Logger = new G4LoggerSettings.G4LoggerSettingsModel
    {
        OutputDirectory = "./logs",
        Type = "Json"
    },
    LogLevel = new Dictionary<string, LogLevel>(StringComparer.OrdinalIgnoreCase)
    {
        ["Default"] = LogLevel.Information
    }
};

var g4Logger = new G4Logger("Demo", () => settings);

The constructor creates the output directory and opens one file per logger name and UTC day, called <name>.<yyyyMMdd>.log. A name that already has a trace listener is not opened a second time. Source: G4Logger.cs:69-78, 351-390.

2. Write entries

The standard methods such as LogInformation and LogError(exception, message) are extension methods on ILogger. G4Logger also declares an event called LogError, so call the methods through an ILogger variable.

ILogger logger = g4Logger;

logger.LogInformation("Application started.");
logger.LogWarning("This is a warning.");
logger.LogError(new InvalidOperationException("An error occurred."), "The operation failed.");

3. Choose the entry format

Type is compared without regard to case. Source: G4Logger.cs:131-137.

Type Entry
Text (default) A readable block with a level code, the time, and one indented line per field. Exceptions are appended.
Json One JSON object per entry with camel-case names: logger, logLevel, timeStamp, machineName, message, exception.
Simple One line: UTC time, a three-letter level code, and the state.
Xml Not implemented. The entry text is a message that tells you to use Json, Text or Simple.

An entry is written as a trace warning for Warning, a trace error for Error and Critical, and a trace information line for everything else. Source: G4Logger.cs:434-455.

4. Choose which levels are written

The rule is in ConfirmLogLevel (G4Logger.cs:204). A level is written when one of these is true:

  • It is Information or higher.
  • It equals the level configured for the logger name.
  • It equals the level configured under Default.

None is never written. Because the comparison is an exact match for the lower levels, setting Default to Debug lets Debug entries through, but Trace entries stay out unless Trace is the configured level.

If EventId in the settings is not zero, only entries with that event id are written. Source: G4Logger.cs:108.

5. React to entries with events

Event Argument When
LogCreating IDictionary<string, object> Before the entry is formatted. You can add or change fields.
LogCreated IDictionary<string, object> After the entry is written.
LogError Exception When writing an entry throws. The exception is not rethrown.

Source: G4Logger.cs:50-60, 144-170.

g4Logger.LogCreating += (sender, entry) => entry["Build"] = "2026.11";
g4Logger.LogCreated += (sender, entry) => Console.WriteLine($"Written: {entry["Message"]}");
g4Logger.LogError += (sender, exception) => Console.WriteLine($"Logging failed: {exception.Message}");

6. Register with dependency injection

using G4.Abstraction.Logging;

using Microsoft.Extensions.Logging;

var factory = LoggerFactory.Create(builder => builder.AddG4Logger(settings =>
{
    settings.G4Logger.Type = "Json";
    settings.G4Logger.OutputDirectory = "./logs";
}));

var logger = factory.CreateLogger("Demo");

AddG4Logger() with no argument registers the provider only. The overload with an action also configures G4LoggerSettings. Source: G4LoggerExtensions.cs:23-45.

Settings from appsettings.json

new G4LoggerSettings() reads the Logging section of appsettings.json in the current directory, then environment variables. It uses four values: LogLevel, G4Logger:AddConsole, G4Logger:AddDebug and G4Logger:OutputDirectory. An output directory of . or an empty value keeps the default, which is the current directory. Source: G4LoggerSettings.cs:14-49.

{
    "Logging": {
        "G4Logger": {
            "OutputDirectory": "./logs",
            "AddConsole": true,
            "AddDebug": false
        },
        "LogLevel": {
            "Default": "Information",
            "G4.Api": "Debug"
        }
    }
}

The constructor does not read Type or EventId from the file. Set those in code or through AddG4Logger(settings => ...).

G4Logger.Instance reads Logging:G4Logger:AddConsole and Logging:G4Logger:AddDebug and adds a console or debug logger beside the G4 logger when they are true. If building the factory fails, Instance is null. Source: G4Logger.cs:393-432.

Limits

  • Log files are not rotated and have no size limit. A file stays open for the life of the process and is named by the UTC day it was opened.
  • The Xml type is not implemented.
  • Scopes are not supported. BeginScope returns nothing (G4Logger.cs:91).

License

This library is released under the Apache License 2.0.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on G4.Abstraction.Logging:

Package Downloads
G4.Extensions

The G4.Extensions namespace provides a versatile set of extension methods designed to enhance functionality across a variety of types, including collections and dictionaries. These extensions facilitate common operations such as converting dictionaries to XML representations, adding items to collections, and retrieving values from dictionaries with default or specified default values.

G4.Plugins

The G4™ Framework Plugins Core package provides essential infrastructure for building extensible plugins within the G4™ automation engine. Developers can create diverse plugins that seamlessly integrate with G4's core functionality.

ClientApp

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2026.11.25.27 35 11/25/2026
2026.11.25.26 80 11/25/2026
2026.11.8.25 1,145 11/8/2026
2026.11.3.24 773 11/3/2026
2026.8.20.23 1,024 8/20/2026
2026.8.20.22 132 8/20/2026
2026.8.20.21 135 8/20/2026
2026.4.29.20 1,458 4/29/2026
2026.3.15.19 513 3/15/2026
2026.3.15.18 155 3/15/2026
2026.2.11.17 417 2/11/2026
2025.3.7.16 1,777 3/7/2025
2025.2.7.15 264 2/7/2025
2025.2.7.14 776 2/7/2025
2025.2.6.13 337 2/6/2025
2025.2.5.12 290 2/5/2025
2025.2.5.11 270 2/5/2025
2025.2.5.10 325 2/5/2025
2025.2.5.9 231 2/5/2025
2025.2.5.8 258 2/5/2025
Loading failed