CodeWF.Log.Core 12.1.0.17

There is a newer version of this package available.
See the version list below for details.
dotnet add package CodeWF.Log.Core --version 12.1.0.17
                    
NuGet\Install-Package CodeWF.Log.Core -Version 12.1.0.17
                    
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="12.1.0.17" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CodeWF.Log.Core" Version="12.1.0.17" />
                    
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 12.1.0.17
                    
#r "nuget: CodeWF.Log.Core, 12.1.0.17"
                    
#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@12.1.0.17
                    
#: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=12.1.0.17
                    
Install as a Cake Addin
#tool nuget:?package=CodeWF.Log.Core&version=12.1.0.17
                    
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 net8.0;net10.0
CodeWF.Log.Extensions.Logging Microsoft.Extensions.Logging Provider 和 AddCodeWF() net8.0;net10.0
CodeWF.Log.Avalonia LogView 和日志通知 net8.0;net10.0

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

Microsoft.Extensions.Logging

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

builder.Logging.AddCodeWF();

默认约定:

  • MEL 自身负责全局级别、Category 级别和多 Provider 编排。
  • CodeWF 默认写入 AppContext.BaseDirectory/logs
  • 普通 ILogger 日志默认是诊断日志,只进入文件等诊断 sink。
  • 用户可见日志通过 LogUserInformation/LogUserWarning/LogUserError/LogUserCritical 表达,并进入 UserLogFeedLogView 和通知。

常用配置使用结构化 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}";

    // Web API 默认已有 Microsoft Console Provider;只有想让 CodeWF 接管控制台格式时才启用。
    options.Console.Enabled = false;
    options.UserLog.Mode = UserLogMode.ExplicitOnly;
    options.Capture.Scopes = true;
    options.Capture.Activity = true;
    options.Queue.Capacity = 10_000;
});

常用模板占位符:TimestampLevelCategoryEventIdEventNameMessageMessageTemplateUserMessagePropertiesUserPropertiesScopesActivityTraceIdSpanIdExceptionNewLine

对应的 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
      },
      "UserLog": {
        "Mode": "ExplicitOnly"
      }
    }
  }
}

如果希望 Web API 控制台也使用 CodeWF 的 OutputTemplate,需要让 CodeWF 接管控制台输出:

builder.Logging.ClearProviders();
builder.Logging.AddCodeWF(options =>
{
    options.Console.Enabled = true;
    options.Console.OutputTemplate =
        "{Timestamp:HH:mm:ss} [{Level:u3}] ({Category}) {Message}{NewLine}{Exception}";
});
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(...) 写入诊断日志,并发布用户安全日志。
  • Logger.Error(message, exception, userMessage) 文件记录技术消息和异常,UI 显示 userMessage
  • Logger.*ToFile(...) 只写诊断日志,不进入 UI、通知或控制台用户输出。
  • Logger.MinimumLevelLoggerOptions.MinimumLevel 使用 MEL 标准 LogLevel

退出前调用:

await Logger.ShutdownAsync();

Avalonia

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,每个视图可以独立按区间显示用户日志。

通知只保留阈值语义:

<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 只接收启用后的新用户日志,不回放历史,也不会接收 *ToFile 日志。

Demos

Demo Purpose
ConsoleLogDemo 验证传统静态 Logger.**ToFile、文件轮转和控制台用户输出。
AvaloniaLogDemo 验证传统静态 Logger.* 接入 Avalonia LogView 和通知。
MicrosoftLoggingAvaloniaDemo 验证 ILogger<T>、DI、AddCodeWF()LogUser*、Avalonia LogView 和通知。
MicrosoftLoggingWebApiDemo 验证 .NET Web API 中的 builder.Logging.AddCodeWF()、普通诊断日志、用户日志、Scope 和 Activity。
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 was computed.  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 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.NetWrapper.FileSystem

File system management and file transfer extension package for CodeWF.NetWrapper.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
12.1.1.1 42 7/30/2026
12.1.0.28 74 7/29/2026
12.1.0.24 104 7/27/2026
12.1.0.21 102 7/27/2026
12.1.0.19 128 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 113 7/22/2026
12.1.0.4 111 7/16/2026
12.1.0.3 113 7/16/2026
12.1.0.1 179 7/14/2026
12.0.5.5 146 6/25/2026
12.0.5.4 125 6/25/2026
12.0.5.3 136 6/24/2026
11.3.14.11 67 7/29/2026
11.3.14.7 97 7/27/2026
11.3.14.4 101 7/27/2026
11.3.14.2 109 7/24/2026
11.3.14.1 145 7/22/2026
Loading failed