AnointedAutomation.Logging
3.0.0
dotnet add package AnointedAutomation.Logging --version 3.0.0
NuGet\Install-Package AnointedAutomation.Logging -Version 3.0.0
<PackageReference Include="AnointedAutomation.Logging" Version="3.0.0" />
<PackageVersion Include="AnointedAutomation.Logging" Version="3.0.0" />
<PackageReference Include="AnointedAutomation.Logging" />
paket add AnointedAutomation.Logging --version 3.0.0
#r "nuget: AnointedAutomation.Logging, 3.0.0"
#:package AnointedAutomation.Logging@3.0.0
#addin nuget:?package=AnointedAutomation.Logging&version=3.0.0
#tool nuget:?package=AnointedAutomation.Logging&version=3.0.0
AnointedAutomation.Logging
Jesus is King ✝️
A small log message model for .NET. LogMessage captures the message, severity, timestamp, program name and calling method, and raises a static event every time one is created so you can route logs wherever you like.
Installation
dotnet add package AnointedAutomation.Logging
- Target framework:
net10.0 - Dependencies: Microsoft.Extensions.Logging.Abstractions (only for the
LogMessageLoggerILogger adapter)
Quick start
using System;
using AnointedAutomation.Optimization.Logging;
// Name your program once at startup; every LogMessage copies it into MessageSource.
LogMessage.MessageSourceSetter = "MyApplication";
// Subscribe once; the event fires from every LogMessage constructor.
LogMessage.LogAdded += (sender, e) =>
{
Console.WriteLine($"{e.Log.timeStamp:O} [{e.Log.messageType}] {e.Log.LocalOperationName}: {e.Log.Message}");
};
LogMessage.Info("Application started.");
LogMessage.Warning(42, "Cache miss rate is high.");
LogMessage.Error("Could not reach the payment provider.");
try { /* ... */ }
catch (Exception ex)
{
LogMessage.Error("Order 1001 capture failed", ex); // keeps the type, inner exceptions and stack
}
Note the namespace: the types live in AnointedAutomation.Optimization.Logging, not AnointedAutomation.Logging.
API overview
All types are in the AnointedAutomation.Optimization.Logging namespace.
LogMessage
| Member | Description |
|---|---|
LogMessage() |
Empty instance for object initializers. Raises no event and stamps nothing: a message built this way never reaches a LogAdded subscriber (your log store or alerts). |
LogMessage(MessageType messageType, string message) |
Sets timeStamp (DateTime.UtcNow), MessageSource, LocalOperationName (stack walk) and raises LogAdded. |
LogMessage(long id, MessageType messageType, string message) |
Same as above, with an id. |
static string MessageSourceSetter |
Program name copied into every new message's MessageSource. |
static event LogAddedEventHandler LogAdded |
Raised whenever a message is constructed with a type and text. Each subscriber runs in isolation: one that throws is reported on Console.Error and never breaks the caller. |
long id |
Optional identifier. |
string LocalOperationName |
Factories: the exact call site as File.Member:line (compiler caller info, no stack walk). Typed constructors: the calling method from the stack (Namespace.Class.Method). |
string Message |
The log text. |
string MessageSource |
Program name (from MessageSourceSetter). |
MessageType messageType |
Severity. |
DateTime timeStamp |
UTC creation time. |
string ExceptionType |
Full type name of the exception passed to an exception overload. |
string CallerMemberName / CallerFilePath / int callerLineNumber |
Call site recorded by the factories. |
string Category / StoreSlug / Properties |
Optional context for bridges and multi-tenant apps (category, tenant, JSON properties). |
Static factory methods, each with a (string message) and a (long id, string message) overload. Critical, Error and Warning also take (string message, Exception exception), which appends the full exception (type, inner exceptions, stack with file:line) to the message:
| Factory | Produces |
|---|---|
LogMessage.Celebrate |
MessageType.Celebrate |
LogMessage.Critical |
MessageType.Critical |
LogMessage.Error |
MessageType.Error |
LogMessage.Info / LogMessage.Informational |
MessageType.Informational |
LogMessage.General |
MessageType.Message (named General because a property and a method cannot both be called Message) |
LogMessage.Success |
MessageType.Success |
LogMessage.Warning |
MessageType.Warning |
LogMessageEventArgs
EventArgs passed to LogAdded; the message is exposed as the Log property. The delegate is LogMessage.LogAddedEventHandler(object sender, LogMessageEventArgs e).
MessageType
enum MessageType : int
| Value | Number | Meaning |
|---|---|---|
Error |
0 | An error that should be investigated |
Warning |
1 | A potential issue |
Success |
2 | A successful operation |
Informational |
3 | General information |
Message |
4 | A general message with no severity |
Critical |
5 | A severe error needing immediate attention |
Celebrate |
6 | A milestone or achievement |
Notes
LogAddedis a static event. EveryLogMessagecreated anywhere in the process reaches every subscriber, so subscribe once and unsubscribe when your listener goes away.- The factories record the caller with
[CallerMemberName]/[CallerFilePath]/[CallerLineNumber]at no runtime cost; only the typed constructors capture aStackTrace. - Since 1.0.7 the package ships an embedded portable PDB, so stack traces through it show file and line.
Related packages
Other AnointedAutomation packages build on this one and expose their own log buffers of LogMessage:
- AnointedAutomation.APIMiddlewares
- AnointedAutomation.Repository.Mongo
- AnointedAutomation.Repository.MySql
Logging (2.1.0)
The package now targets net10.0 and net472, so the classic ASP.NET package AnointedAutomation.SSO.Owin can log through LogMessage. The two Console.Error writes inside this library (a subscriber that throws, and a property whose ToString throws) are deliberate last-resort output: logging them through LogMessage would re-enter the pipeline and could recurse.
License
MIT. See LICENSE.
Support This Project
This library is free and open source. The best way to support the work is to shop with us:
- Christian items: https://store.anointed.company
- Pets: https://www.animaldander.com
- Everything else: https://www.mart.club
Found a bug or have a request? Open an issue at https://github.com/AnointedAutomation/AnointedAutomation/issues.
Structured logging (1.1.0)
// Up to four properties inline; they land in StructuredProperties and, as JSON, in Properties.
LogMessage.Warning($"Refund failed for order {orderId}", ex, ("orderId", orderId), ("store", storeSlug));
LogMessage.Debug($"cache miss {key}"); // MessageType.Debug = 7, Trace = 8 (appended, never renumbered)
// Scopes flow through awaits and tasks (AsyncLocal); inner scopes and call-site values win on a repeated key.
using IDisposable scope = LogMessage.Scope(("orderId", orderId));
// Category is the caller file name ("OrderService") by default; For<T>() stamps the type's full name instead.
private static readonly LogSource Log = LogMessage.For<OrderService>();
Log.Error("capture failed", ex, ("orderId", orderId));
| Type | Purpose |
|---|---|
LogStoreCapture |
Test helper: using LogStoreCapture capture = LogStoreCapture.Start(); records the messages of the current async flow only, so parallel xUnit/NUnit tests never see each other's logs. Entries, OfLevel, Contains. |
LogStoreThrottle |
Shared store throttle: 5 identical rows, 50 per template (200 for Errors) per 10-minute window, Critical never throttled; TakeSummaries(force) returns one summary per key that suppressed rows. |
LogMessageLogger / LogMessageLoggerProvider |
ILogger adapter for third-party APIs that require one; writes through LogMessage with state pairs as properties. |
Startup ordering (opt-in): call LogMessage.BufferUntilFirstSubscriber() first thing in Main; messages raised before the
first LogAdded subscriber attaches are then buffered (up to LogMessage.PreSubscriptionBufferCapacity, 1000; oldest
dropped) and delivered to that subscriber, followed by one Warning with the dropped count if any were dropped. Off by
default, so libraries and test runs never hold or replay stale messages. LogAdded handlers run synchronously on the logging thread: keep them fast and
queue any I/O.
PascalCase members (3.0.0, breaking)
LogMessage follows the Anointed hybrid casing rule: reference-type members are PascalCase, value-type members stay camelCase.
| Before | Now |
|---|---|
localOperationName, message, messageSource, exceptionType, callerMemberName, callerFilePath, category, storeSlug, properties, structuredProperties |
LocalOperationName, Message, MessageSource, ExceptionType, CallerMemberName, CallerFilePath, Category, StoreSlug, Properties, StructuredProperties |
LogMessageEventArgs.log |
LogMessageEventArgs.Log |
LogMessage.Message(...) factory (every overload) |
LogMessage.General(...), because a type cannot have a property and a method both named Message |
id, messageType, timeStamp, callerLineNumber |
unchanged |
The serialized names change with the members, and nothing pins the old ones. Under the Anointed hybrid casing (plain System.Text.Json, Newtonsoft.Json with the default resolver, JsonCasingConvention, MongoDB with HybridElementNameConvention) the reference members are written Message, MessageSource, LocalOperationName, ExceptionType, CallerMemberName, CallerFilePath, Category, StoreSlug and Properties, and the value members stay id, messageType, timeStamp and callerLineNumber. A camelCase naming policy or resolver writes all of them camelCase (message and so on). Consumers that read raw logs, for example Perilous APILogging output, must switch to the new field names, and documents stored under the old lowercase names no longer match. StructuredProperties is still ignored by System.Text.Json and still written by Newtonsoft.Json and the MongoDB driver.
Nullable reference types (2.0.0)
The package is compiled with nullable reference types enabled. API nullability changes, which can surface new warnings in consumers that have nullable enabled:
LogMessagepropertieslocalOperationName,message,messageSource,exceptionType,callerMemberName,callerFilePath,category,storeSlugandpropertiesare nowstring?, andstructuredPropertiesisIReadOnlyDictionary<string, object?>?. A message from the default constructor or an object initializer stamps nothing, and the exception, caller and category fields are null when not supplied.- Every factory and
LogSourcemethod takesstring? message(a null message is logged as null, as before) andException? exception(null logs the message alone). - Structured property tuples are
(string Key, object? Value): a null value is written as JSON null.LogMessage.Scope(params (string Key, object? Value)[])follows. LogMessageLogger.LogmatchesILogger:Exception? exceptionandFunc<TState, Exception?, string> formatter.LogStoreThrottle.TryPass(string category, MessageType level, string? template, string rendered):templateis nullable; a nullcategorynow throwsArgumentNullException(previously it was accepted).LogMessageEventArgs(LogMessage logMessage)now throwsArgumentNullExceptionfor null (previously it stored null).LogMessage.For<T>()throwsInvalidOperationExceptionwhen the type has no full name (previously it passed null on).
| Product | Versions 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. |
| .NET Framework | net472 is compatible. net48 was computed. net481 was computed. |
-
.NETFramework 4.7.2
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.15)
- System.Text.Json (>= 8.0.6)
-
net10.0
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.15)
NuGet packages (12)
Showing the top 5 NuGet packages that depend on AnointedAutomation.Logging:
| Package | Downloads |
|---|---|
|
AnointedAutomation.Repository.Mongo
A MongoDB helper and generic repository base for .NET, with CRUD, paging, aggregation, index management, BSON class maps and casing conventions. |
|
|
AnointedAutomation.Objects.API
ASP.NET Core helpers: an in memory IFormFile, a hybrid casing System.Text.Json naming convention, and a GraphQL response envelope reader. |
|
|
AnointedAutomation.APIMiddlewares
ASP.NET Core middleware and filters for API key authentication, IP blacklisting, country blocking, honeypot and bot defense (nothing is on by default; see the README), invalid endpoint tracking and idle time memory cleanup. |
|
|
AnointedAutomation.Memory
On demand garbage collection helper that forces a full collection and tries to return unused memory to the operating system. |
|
|
AnointedAutomation.Serialization
Shared serialization helpers: naming rules (camel, Pascal, snake and the hybrid value/reference casing rule), System.Text.Json casing convention, presets and UTC DateTime converter, tolerant Newtonsoft.Json converters, and lenient JsonElement readers. No MongoDB dependency. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 3.0.0 | 258 | 11/30/2026 |
| 2.0.0 | 277 | 11/29/2026 |
| 1.1.1 | 1,028 | 11/18/2026 |
| 1.1.0 | 1,664 | 11/13/2026 |
| 1.0.8 | 4,468 | 11/4/2026 |
| 1.0.6 | 756 | 10/26/2026 |
| 1.0.5 | 608 | 10/1/2026 |
| 1.0.4 | 181 | 10/1/2026 |
| 1.0.3 | 305 | 9/25/2026 |
| 1.0.2 | 663 | 8/23/2026 |
| 1.0.1 | 1,293 | 5/30/2026 |
| 1.0.0 | 1,046 | 3/15/2026 |
| 0.0.10 | 334 | 3/13/2026 |
| 0.0.9 | 222 | 3/11/2026 |
| 0.0.8 | 794 | 2/17/2026 |