BonyadCode.Logger.AspNetCore 1.0.1

dotnet add package BonyadCode.Logger.AspNetCore --version 1.0.1
                    
NuGet\Install-Package BonyadCode.Logger.AspNetCore -Version 1.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="BonyadCode.Logger.AspNetCore" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="BonyadCode.Logger.AspNetCore" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="BonyadCode.Logger.AspNetCore" />
                    
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 BonyadCode.Logger.AspNetCore --version 1.0.1
                    
#r "nuget: BonyadCode.Logger.AspNetCore, 1.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.
#:package BonyadCode.Logger.AspNetCore@1.0.1
                    
#: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=BonyadCode.Logger.AspNetCore&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=BonyadCode.Logger.AspNetCore&version=1.0.1
                    
Install as a Cake Tool

In the name of God

BonyadCode.Logger.AspNetCore

A flexible, structured logging utility built on Serilog — designed for ASP.NET Core applications. Supports predefined and custom log types with categorized log paths, output templates, and log levels. Ideal for capturing detailed application traces, failures, exceptions, and custom audit trails.


✨ Features

  • Categorized Logging: Logs organized by type, purpose, and file path.
  • Predefined Log Types: Built-in enums for common app scenarios (e.g., Startup, Exceptions, Traces).
  • Custom Log Types: Define your own log types with full control over paths, levels, and formatting.
  • Exception Logging: Automatically capture and serialize exception details.
  • Simple Integration: Log with a single method call — no need for boilerplate setup.

📦 Installation

dotnet add package BonyadCode.Logger.AspNetCore

🚀 Quick Examples

✅ Log a Startup Message (using built-in type)

using BonyadCode.Logger.AspNetCore;

await LogBuilder.LogAsync(
    PredefinedLogTypes.Get(ELogType.Startup),
    new { Message = "Application has started." }
);

✅ Log an Exception (using built-in type)

try
{
    // Risky code
}
catch (Exception ex)
{
    await LogBuilder.LogExceptionAsync(
        PredefinedLogTypes.Get(ELogType.Exception),
        ex
    );
}

✅ Log with a Custom Log Type

public class AuditLogType : ILogType
{
    public string Name => "Audit";
    public string GetPath(string? logId) =>
        Path.Combine("custom-logs", "audit", $"audit_{logId}_.log");

    public LogEventLevel GetLogEventLevel() => LogEventLevel.Information;
    public RollingInterval GetRollingInterval() => RollingInterval.Day;

    public string GetOutputTemplate() =>
        "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [AUDIT] {Message:lj}{NewLine}{Exception}";
}

// Use it:
var audit = new AuditLogType();
await LogBuilder.LogAsync(audit, new { User = "admin", Action = "Deleted item #42" });

📘 Predefined Log Types

Enum Value Folder Path Level Rolling
Default app-logs/default Verbose Hour
Startup app-logs/startup Information Hour
StartupException app-logs/startup/exceptions Fatal Minute
TraceLog app-logs/tracelogs Information Hour
TraceLogException app-logs/tracelogs/exceptions Error Minute
TraceLogFailure app-logs/tracelogs/failures Fatal Minute
Exception app-logs/exceptions Error Minute
ExceptionDatabase app-logs/exceptions/database Fatal Minute
ExceptionDataTamper app-logs/exceptions/datatamper Fatal Minute
ExceptionFailure app-logs/exceptions/failure Fatal Minute
Failure app-logs/failures Fatal Minute

Retrieve via:

var logType = PredefinedLogTypes.Get(ELogType.TraceLog);

⚙️ How It Works

  • Logs are written using Serilog to file.

  • Log types (via ILogType) define how/where logs are saved:

    • File path
    • Log level
    • Rolling interval
    • Output template
  • Logs are formatted with timestamp boundaries and serialized objects or exceptions.


🧹 Extension Points

You can register your own log types simply by implementing the ILogType interface:

public interface ILogType
{
    string Name { get; }
    string GetPath(string? logId);
    LogEventLevel GetLogEventLevel();
    RollingInterval GetRollingInterval();
    string GetOutputTemplate();
}

🧪 Optional Synchronous Usage

If you prefer fire-and-forget, the methods are safe to call without await:

_ = LogBuilder.LogAsync(...);

You may also provide a synchronous wrapper in your project:

public static void Log(ILogType type, object log) =>
    Task.Run(() => LogBuilder.LogAsync(type, log));

🤝 Contributing

Issues, ideas, and PRs are welcome! Star the repo or submit improvements at GitHub →


📄 License

Apache 2.0 — see the LICENSE file.


Usage Conditions:

  • This program must not be used for any military or governmental purposes without the owner's consent.
  • This program must not be used for any inhumane purposes.
  • This program must not be used for any illegal or haram activities.
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  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

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.1 111 6/8/2025
1.0.0 101 6/7/2025