CodeWF.Log.Core 11.3.14.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package CodeWF.Log.Core --version 11.3.14.2
                    
NuGet\Install-Package CodeWF.Log.Core -Version 11.3.14.2
                    
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="CodeWF.Log.Core" Version="11.3.14.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CodeWF.Log.Core" Version="11.3.14.2" />
                    
Directory.Packages.props
<PackageReference Include="CodeWF.Log.Core" />
                    
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 CodeWF.Log.Core --version 11.3.14.2
                    
#r "nuget: CodeWF.Log.Core, 11.3.14.2"
                    
#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 CodeWF.Log.Core@11.3.14.2
                    
#: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=CodeWF.Log.Core&version=11.3.14.2
                    
Install as a Cake Addin
#tool nuget:?package=CodeWF.Log.Core&version=11.3.14.2
                    
Install as a Cake Tool

CodeWF.Log

NuGet NuGet NuGet License

CodeWF.Log 是面向 .NET 和 Avalonia 的轻量日志组件。新版本以 Microsoft.Extensions.Logging 为主入口,同时保留 Logger.Info/Warn/Error/FatalLogger.*ToFile<log:LogView /> 等原有常用方式,方便旧项目逐步迁移。

Packages

Package Purpose Targets
CodeWF.Log.Core 文件/控制台日志、完整事件 Feed、静态 Logger API net10.0
CodeWF.Log.Extensions.Logging Microsoft.Extensions.Logging Provider 和 AddCodeWF() net10.0
CodeWF.Log.Avalonia LogView 和日志通知 net10.0

运行 pack.bat 可将三个包输出到 artifacts/packages

Microsoft.Extensions.Logging

推荐新项目使用标准 .NET 日志入口:

builder.Logging.AddCodeWF();

默认约定:

  • MEL 自身负责全局级别、Category 级别和多 Provider 编排。
  • CodeWF 默认写入 AppContext.BaseDirectory/logs
  • 普通 ILoggerLogUser* 都生成完整 CodeWFLogEvent,进入启用的 File、Console 和 LogEventFeed
  • LogUser* 只额外提供 UserMessage;模板中的 {UserMessage} 为空白时回退 {Message}
  • File 使用独立 OutputTemplate;Console、LogView 和通知严格共享 LineTemplate
  • 两类模板都可通过各自的 Controller 显式、原子地运行时更新;其他 Pipeline 配置仍需重启生效。

常用配置使用结构化 Options;日志格式由 OutputTemplate 决定,不提供 IncludeEventIdIncludeScopes 这类开关。模板里写了对应占位符就输出,没有写就忽略:

builder.Logging.AddCodeWF(options =>
{
    options.File.Enabled = true;
    options.File.DirectoryPath = "Log";
    options.File.OutputTemplate =
        "{Timestamp:yyyy-MM-dd HH:mm:ss.fff} [{Level:u3}] ({Category}) {Message} {Properties}{NewLine}{Exception}";

    options.LineTemplate =
        "{Timestamp:HH:mm:ss} [{Level:u3}] ({Category}) {UserMessage}{NewLine}";

    options.Console.Enabled = false;
    options.Capture.Scopes = true;
    options.Capture.Activity = true;
    options.Queue.Capacity = 10_000;
});

常用模板占位符:TimestampLevelCategoryEventIdEventNameMessageMessageTemplateUserMessagePropertiesScopesActivityTraceIdSpanIdExceptionNewLine

对应的 appsettings.json

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    },
    "CodeWF": {
      "LogLevel": {
        "Default": "Trace",
        "Microsoft.AspNetCore": "Warning"
      },
      "File": {
        "Enabled": true,
        "DirectoryPath": "Log",
        "OutputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff} [{Level:u3}] ({Category}) {Message} {Properties}{NewLine}{Exception}"
      },
      "Console": {
        "Enabled": false
      },
      "LineTemplate": "{Timestamp:HH:mm:ss} [{Level:u3}] ({Category}) {UserMessage}{NewLine}",
      "EventFeed": {
        "Enabled": true,
        "RecentCapacity": 2000
      }
    }
  }
}

如果希望控制台统一使用 CodeWF 的 LineTemplate,应避免同时注册其他 Console Provider:

builder.Logging.ClearProviders();
builder.Logging.AddCodeWF(options =>
{
    options.Console.Enabled = true;
    options.LineTemplate =
        "{Timestamp:HH:mm:ss} [{Level:u3}] ({Category}) {UserMessage}{NewLine}";
});
logger.LogError(ex, "Failed to parse task file {TaskPath}", taskPath);

logger.LogUserError(
    ex,
    "任务文件加载失败,请检查文件格式后重新打开。",
    "Failed to parse task file {TaskPath}",
    taskPath);

Legacy Static API

非 Host 场景仍可使用 Logger.Initialize(...)

Logger.Initialize(new LoggerOptions
{
    MinimumLevel = LogLevel.Debug,
    EnableConsole = true,
    File = new FileLogOptions
    {
        DirectoryPath = Path.Combine(AppContext.BaseDirectory, "Log")
    }
});

静态 API 约定:

  • Logger.Info/Warn/Error/Fatal(...) 写入完整事件;userMessage 是同一事件上的可选字段。
  • Logger.Error(message, exception, userMessage) 分别保存诊断消息、异常快照和用户消息。
  • Logger.*ToFile(...) 只写文件,不进入 Console、LogView 或通知。
  • Logger.MinimumLevelLoggerOptions.MinimumLevel 使用 MEL 标准 LogLevel

退出前调用:

await Logger.ShutdownAsync();

运行时切换格式时,DI 场景注入 ILineTemplateControllerIFileOutputTemplateController;静态 API 场景使用 Logger.Events.LineTemplateLogger.FileOutputTemplate。模板校验失败时当前有效格式保持不变。

Avalonia

v11.3.14 分支支持 Avalonia [11.3.14, 12.0.0),组件包版本为 11.3.14.x

XAML 命名空间保持不变:

<Window
    xmlns="https://github.com/avaloniaui"
    xmlns:log="https://codewf.com">
    <log:LogView
        MinimumLevel="Information"
        MaximumLevel="Critical"
        MaxDisplayCount="1000" />
</Window>

LogView.MinimumLevelLogView.MaximumLevel 都是 Microsoft.Extensions.Logging.LogLevel,每个视图可以独立按区间显示完整事件。默认范围为 Information 至 Critical。

右键“查看日志”使用应用级 LogContext.LogDirectory,也可由单个 LogView.LogDirectory 覆盖。该路径与事件 Source 独立,适合 CodeWF 只负责界面、Serilog 负责文件的多 Provider 场景:

LogContext.SetLogDirectory(this, Path.GetFullPath("Log"));

通知只保留阈值语义:

<Application
    xmlns="https://github.com/avaloniaui"
    xmlns:log="https://codewf.com"
    log:LogNotifications.Mode="DesktopWindow"
    log:LogNotifications.MinimumLevel="Error"
    log:LogNotifications.Duration="00:00:10"
    log:LogNotifications.ApplicationName="CodeWF Log Demo" />

LogNotifications 只按 MinimumLevel 接收启用后的新事件,不回放历史,也不会接收 *ToFile 日志。InApp 默认最多同时显示 3 条;DesktopWindow 复用一个桌面右下角窗口。

Demos

Demo Purpose
ConsoleLogDemo 验证传统静态 Logger.**ToFile、文件轮转和控制台用户输出。
AvaloniaLogDemo 验证传统静态 Logger.*、LineTemplate/OutputTemplate 切换、Avalonia LogView 和通知。
MicrosoftLoggingAvaloniaDemo 验证 ILogger<T>、DI、AddCodeWF()、两类模板切换、Avalonia LogView 和通知。
MicrosoftLoggingWebApiDemo 验证 .NET Web API 中的 builder.Logging.AddCodeWF()、普通诊断日志、用户日志、Scope 和 Activity。
MultiProviderAvaloniaDemo 验证 Serilog 负责文件/控制台、CodeWF 负责 LogView/通知和 LineTemplate 切换,以及私有 UserMessage 元数据隔离。
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 (6)

Showing the top 5 NuGet packages that depend on CodeWF.Log.Core:

Package Downloads
CodeWF.LogViewer.Avalonia

面向 Avalonia 的 C# 日志查看控件,基于 CodeWF.Log.Core 展示实时日志、级别信息和界面友好内容,适合桌面应用内嵌日志观察台。

CodeWF.NetWrapper

CodeWF.NetWrapper builds on CodeWF.NetWeaver and provides TCP/UDP helpers and command dispatching for socket applications.

CodeWF.EventBus.Socket

基于 Socket 实现的分布式事件总线,不依赖第三方 MQ。

CodeWF.Log.Avalonia

面向 Avalonia 的 C# 日志查看控件,基于 CodeWF.Log.Core 展示实时日志、级别信息和界面友好内容,适合桌面应用内嵌日志观察台。

CodeWF.Log.Extensions.Logging

Microsoft.Extensions.Logging provider for CodeWF.Log.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
12.1.1.1 46 7/30/2026
12.1.0.28 76 7/29/2026
12.1.0.24 107 7/27/2026
12.1.0.21 105 7/27/2026
12.1.0.19 132 7/27/2026
12.1.0.18 122 7/24/2026
12.1.0.17 163 7/23/2026
12.1.0.16 174 7/23/2026
12.1.0.7 114 7/22/2026
12.1.0.4 112 7/16/2026
12.1.0.3 113 7/16/2026
12.1.0.1 180 7/14/2026
12.0.5.5 146 6/25/2026
12.0.5.4 126 6/25/2026
12.0.5.3 136 6/24/2026
11.3.14.11 70 7/29/2026
11.3.14.7 99 7/27/2026
11.3.14.4 101 7/27/2026
11.3.14.2 110 7/24/2026
11.3.14.1 145 7/22/2026
Loading failed