TCIS.Logging.Hosting.WinForms 1.0.8-rc.7

This is a prerelease version of TCIS.Logging.Hosting.WinForms.
dotnet add package TCIS.Logging.Hosting.WinForms --version 1.0.8-rc.7
                    
NuGet\Install-Package TCIS.Logging.Hosting.WinForms -Version 1.0.8-rc.7
                    
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="TCIS.Logging.Hosting.WinForms" Version="1.0.8-rc.7" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TCIS.Logging.Hosting.WinForms" Version="1.0.8-rc.7" />
                    
Directory.Packages.props
<PackageReference Include="TCIS.Logging.Hosting.WinForms" />
                    
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 TCIS.Logging.Hosting.WinForms --version 1.0.8-rc.7
                    
#r "nuget: TCIS.Logging.Hosting.WinForms, 1.0.8-rc.7"
                    
#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 TCIS.Logging.Hosting.WinForms@1.0.8-rc.7
                    
#: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=TCIS.Logging.Hosting.WinForms&version=1.0.8-rc.7&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=TCIS.Logging.Hosting.WinForms&version=1.0.8-rc.7&prerelease
                    
Install as a Cake Tool

TCIS.Logging.Hosting.WinForms

Log tập trung cho ứng dụng WinForms trên .NET Framework (net472, net48). Gói mỏng dựng trên TCIS.Logging.Hosting: dùng chung composition và lifecycle coordinator với host IIS, thêm phần riêng desktop — writer đệm trước khi host sẵn sàng (TLog.Writer), bắt lỗi toàn cục, ghi thao tác người dùng, theo dõi form, watchdog UI treo, mã hỗ trợ cho dialog lỗi, outbox gửi về Log Collector.

using System;
using System.Windows.Forms;
using TCIS.Logging.Hosting.WinForms;

[STAThread]
static void Main()
{
    using (TDesktopLoggingHost.Start(desktop =>
    {
        desktop.OnThreadException = (sender, e) => ShowError(e.Exception);
    }))
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new MainForm());
    }
}

Mẫu trên dùng khối using (...) { } vì project kiểu cũ (packages.config, net472) mặc định C# 7.3 — dạng using var x = ...; là C# 8. App không có handler Application.ThreadException thì gọi TDesktopLoggingHost.Start() không tham số (lib ghi log rồi giữ hộp thoại mặc định của WinForms).

TDesktopLoggingHost.Start trả về ngay (host dựng trên thread nền) và không tạo window handle; Dispose cuối Main (trên UI thread) để drain xuống đĩa và gửi nốt về collector. Một host sống mỗi process, loại trừ với TLoggingHost.RunFramework (CONFIG_LOG_HOST_CONFLICT). App vẫn Application.ThreadException += … sau Start thì lib ghi một WARN CONFIG_LOG_THREAD_EXCEPTION_REPLACED — chuyển handler vào desktop.OnThreadException.

Phiên bản: mọi gói TCIS.Logging*, TCIS.Core, TCIS.Observability.Classification phụ thuộc nhau theo phiên bản chính xác ([x.y.z]) vì dùng internal của nhau — cài một mình gói này, NuGet kéo đúng phần còn lại; không nâng lẻ một gói.

Secret: để LogCollector:ClientSecret trống trong appsettings.json, cấp qua biến môi trường LogCollector__ClientSecret. Dialog lỗi: chỉ gọi TLog.GetSupportCode(ex) (tự log nếu chưa log) — gọi kèm TLog.Writer.LogException(ex) có thể ghi đúp. Chẩn đoán nội bộ: {DataRoot}\logs\diagnostics-*.log (tối đa 3 × 1 MiB).

Giá trị ô nhập trong breadcrumb

Ngoài thao tác và form, custom.breadcrumbs mang giá trị người dùng chốt (kind = "input", name = "{Form}.{Control}", value), theo ba mức:

  1. Trạng thái chọn (CaptureSelectionValues, mặc định bật): CheckBox/RadioButton ("true"/"false"), ComboBox DropDownList, ListBox, DevExpress CheckEdit/ToggleSwitch/LookUpEdit/GridLookUpEdit/SearchLookUpEdit/ImageComboBoxEdit/ ComboBoxEdit không cho gõ (text hiển thị của mục chọn). Nhóm LookUp chỉ ghi khi mục đã chọn (EditValue) đổi, không ghi chữ gõ để tìm.
  2. Ô nhập tự do: chỉ ô có tên khớp CaptureInputValues (không phân biệt hoa thường, * wildcard; mặc định rỗng = tắt).
  3. Mật khẩu: không bao giờ ghi (PasswordChar/UseSystemPasswordChar, kể cả trên Properties/MaskBox của DevExpress, hoặc tên có từ pass/pwd/pw/pin/otp/passcode, hay chứa password/passwd/matkhau/secret), kể cả khi khớp danh sách. So theo từ của tên (camelCase, _, -; bỏ tiền tố txt/edt/te…): txtPass, txtpin, OTPCode bị chặn; txtShippingLine, txtCompass thì không.
"TLogSettings": { "Desktop": { "CaptureSelectionValues": true, "CaptureInputValues": [ "frmC01_ContainerMaint.txtContainerNo", "*.txtVesselCode" ] } }

Chốt khi focus rời ô, trước mỗi lệnh (Enter/F-key/click, kể cả nút Bar DevExpress không lấy focus), và với mức 1 ngay khi đổi; chỉ khi giá trị khác lúc ô nhận focus. Giá trị trim, tối đa 64 ký tự + …. Khoá CaptureInputValues trong cấu hình thay thế danh sách gán bằng code. ⚠️ Chỉ đưa vào danh sách ô không chứa dữ liệu cá nhân — giá trị chỉ được che theo mẫu (số điện thoại, email…), tên người/địa chỉ không bị che. Ô trong GridControl (lưới tự vẽ) chưa được hỗ trợ. Lib không tham chiếu DevExpress (nhận diện theo tên kiểu + reflection). Chi tiết: mục 4.1 của hướng dẫn tích hợp.

breadcrumbs[].at cùng định dạng @timestamp (yyyy-MM-ddTHH:mm:ss.fffZ); danh sách sắp theo at tăng dần.

API công khai

Kiểu Vai trò
TDesktopLoggingHost.Start(Action<DesktopLoggingBuilder>?) Điểm vào; trả IDisposable
DesktopLoggingBuilder Configuration (mặc định appsettings.json cạnh exe + biến môi trường), Services, Options, ResolveSecret, OnThreadException
DesktopLoggingOptions Bind từ TLogSettings:Desktop: DataDirectory, SlowActionThreshold (2 s), UiHangThreshold (5 s), BreadcrumbCapacity (20), AttachBreadcrumbsToSlowActions (false — bật để WARN thao tác chậm mang breadcrumb khi phân tích chỗ chậm), CrashFlushBudget (2 s), TrackUserActions (true), EnableUiWatchdog (true), CaptureSelectionValues (true), CaptureInputValues (rỗng)
TLog.Writer ILogWriter tĩnh, dùng được trước khi host sẵn sàng (đệm rồi phát lại)
TLog.ConfigureCollector(Action<LogCollectorOptions>) Nạp cấu hình collector lúc chạy (vd. từ DB)
TLog.SetSessionContext(siteCode, userId, tenantId, userName) Ngữ cảnh phiên cho mọi bản ghi sau đó
TLog.TrackForm(Form) Ghi form mở/đóng, mỗi sự kiện là một breadcrumb
TLog.GetSupportCode(Exception) Mã hỗ trợ 8 ký tự cho dialog lỗi
IUserActionNameResolver Điểm mở rộng đặt tên thao tác cho control không có HWND từng item

Gửi log về collector dùng LogCollectorOptions/ICollectorConfiguration/ICollectorShipperStatus của TCIS.Logging (section LogCollector, xem README của gói đó).

Hướng dẫn tích hợp đầy đủ (cài NuGet, cấu hình, ba điểm sửa, so sánh trường với BE, giới hạn đã biết): TCIS.Logging.Hosting.WinForms. Sample: src/samples/TCIS.Logging.Hosting.WinForms.Sample.

Product Compatible and additional computed target framework versions.
.NET Framework net472 is compatible.  net48 is compatible.  net481 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.8-rc.7 0 10/27/2026
1.0.8-rc.6 0 10/27/2026