TCIS.Logging.Autofac
1.0.9
dotnet add package TCIS.Logging.Autofac --version 1.0.9
NuGet\Install-Package TCIS.Logging.Autofac -Version 1.0.9
<PackageReference Include="TCIS.Logging.Autofac" Version="1.0.9" />
<PackageVersion Include="TCIS.Logging.Autofac" Version="1.0.9" />
<PackageReference Include="TCIS.Logging.Autofac" />
paket add TCIS.Logging.Autofac --version 1.0.9
#r "nuget: TCIS.Logging.Autofac, 1.0.9"
#:package TCIS.Logging.Autofac@1.0.9
#addin nuget:?package=TCIS.Logging.Autofac&version=1.0.9
#tool nuget:?package=TCIS.Logging.Autofac&version=1.0.9
TCIS.Logging.Autofac
A module supporting AOP (Aspect-Oriented Programming) for the logging system in TCIS, utilizing the Autofac library.
🌟 Overview
TCIS.Logging.Autofac replaces the default .NET DI Container with Autofac. Specifically, it provides:
- Assembly Scanning: Automatically scans and registers Services by Suffixes.
- AOP Interception: Automatically intercepts function calls to consistently log input parameters, execution time, and exceptions, without requiring repetitive logging code in the Business Logic.
📦 Installation
Install the package via .NET CLI:
dotnet add package TCIS.Logging.Autofac
⚙️ Configuration (appsettings.json)
You can customize AOP configurations (e.g., the list of suffixes to auto-register) in the TLogSettings:AopSettings section (default):
{
"TLogSettings": {
"AopSettings": {
"DiRegistrationSuffixes": [ "Service", "Repository", "Manager" ]
}
}
}
Lọc field của data.result
IncludedSuffixes rỗng hoặc * chọn tất cả lớp nghiệp vụ đủ điều kiện trong TargetNamespaces.
Ranh giới bảo vệ vẫn áp dụng: không proxy IHostedService/BackgroundService, startup filter,
HttpClient builder filter, EventBus serializer/invoker hoặc chính hạ tầng logging/capture.
Proxy interface có thể che kiểu BackgroundService, làm host mất giám sát lỗi; các hook còn
nhận/trả delegate hoặc metadata vận chuyển không phù hợp để serialize như DTO nghiệp vụ.
Kiểm tra này áp dụng cả instance do factory trả về và module Pluggable.
Worker vẫn có thể gọi ILogWriter và các service nghiệp vụ được intercept; capture HTTP/queue
tiếp tục dùng adapter tại boundary tương ứng.
TLogInterceptor là nơi duy nhất áp bộ lọc field của kết quả (ResultIncludeFields, ResultIncludeFieldsByMethod,
ResultFilterMaxItems trong TLogSettings). Ví dụ:
{
"TLogSettings": {
"ResultIncludeFields": ["id", "code", "cd"],
"ResultIncludeFieldsByMethod": { "OrderService.Get": ["id"] }
}
}
- Rỗng hoặc có
"*"= ghi hết; khai báo toàn mục rỗng/gõ nhầm = không ghi result (fail-closed). KhoáByMethoddùng tên lớp hiện thực (ClasshoặcClass.Method, không phân biệt hoa thường). - Duyệt vét cạn mọi tầng object/list lồng nhau; field khớp được giữ nguyên cả giá trị; phần tử list không có field nào bị bỏ.
- Che dữ liệu nhạy cảm luôn thắng; lọc chạy trước
ResponseSizevàResponseSummary. - Quyết định lọc được cache theo phương thức của lớp hiện thực (chung nơi cache
ExcludeClasses/ExcludeMethods). - Controller (
ControllerLoggingFilter), gRPC vàTLogWriterchưa lọc — chỉ AOP.
Chi tiết đầy đủ: README của TCIS.Logging.
Chẩn đoán treo (LogInvocationStart, SlowCallThreshold)
Log AOP (TLogInterceptor) chỉ ghi khi Proceed() trả về (trong finally). Một lời gọi treo — chờ DB, lock,
HTTP không timeout — vì thế không để lại bản ghi nào. Hai tuỳ chọn trong TLogSettings bù chỗ này:
{
"TLogSettings": {
"LogInvocationStart": true,
"InvocationStartLevel": "INFO",
"SlowCallThreshold": "00:00:30"
}
}
| Khoá | Mặc định | Ý nghĩa |
|---|---|---|
LogInvocationStart |
false |
Ghi bản ghi "{Class}.{Method} started" trước Proceed(): không có data, event.outcome: "unknown", cùng event.id với bản ghi kết thúc. |
InvocationStartLevel |
"DEBUG" |
Mức của bản ghi started. Mặc định DEBUG sẽ bị admission loại khi min level là INFO (mặc định của lib) — hoặc hạ min level bằng Dynamic Log Level, hoặc đặt "INFO" khi cần điều tra mà không muốn hạ cả hệ thống. |
InvocationSuccessLevel |
"INFO" |
Mức của bản ghi kết thúc một lời gọi thành công. Lỗi vẫn ghi WARN/ERROR theo loại, cảnh báo chậm vẫn WARN. Đặt "DEBUG" cho host gọi lặp cùng một việc (worker quét lại hàng chờ): bản ghi thành công dưới min level không được dựng, nên tiết kiệm cả serialize. Phải là TRACE…FATAL — sai thì khởi động lỗi (ValidateOnStart). |
SlowCallThreshold |
null (tắt) |
Lời gọi chạy quá ngưỡng mà chưa kết thúc ⇒ một bản ghi WARN "{Class}.{Method} still running after {ms}ms", event.outcome: "unknown", event.duration = ms đã trôi, cùng event.id với bản ghi kết thúc. <= 0 cũng là tắt. |
Cơ chế và giới hạn:
- Một sweeper dùng chung (một
Timer, chu kỳ 1 giây, tạo lười) quét các lời gọi đang chạy — độ phân giải ~1 giây, không phải mili giây; không tạo Timer cho từng lời gọi. WARN bắn đúng một lần, không lặp theo bội số ngưỡng. - Ngữ cảnh (WorkContext, Activity) được chụp trên thread gọi lúc bắt đầu nên WARN vẫn mang đúng transaction/user dù sweeper chạy ở thread khác. WARN không bắn sau khi hàm đã hoàn tất; hàm xong trước ngưỡng thì không có WARN.
- Hàm chạy lâu một cách hợp lệ (job, export) sẽ sinh WARN: loại chúng bằng
ExcludeClasses/ExcludeMethods(đường bị loại không đăng ký sổ đang chạy). Khuyến nghị bậtSlowCallThresholdcho API đồng bộ, không bật toàn cục mù quáng. - Cách đọc log: thấy
WARN ... still runningmà chưa có bản ghi kết thúc cùngevent.id⇒ lời gọi đã vào hàm và đang treo. Phạm vi: cả ba đường — hàm đồng bộ,Task,Task<T>; chỉTLogInterceptor(controller/gRPC không có). - Giới hạn khi thread pool cạn: sweeper chạy trên thread pool. Đúng lúc thread pool bị bão hoà (thường đi kèm treo) callback có thể bị trễ hoặc không chạy, khi đó không có WARN — không có WARN chưa chứng minh là không treo.
event.iddùng chung cho started/WARN/kết thúc. Nếu pipeline phía sau (Filebeat/Logstash/ES ingest) đặt_idhoặc dedupe theoevent.id, bản ghi kết thúc sẽ đè bản ghi treo. Thư viện không dùngevent.idlàm khoá chống trùng (dùngRecordIdriêng cho spool/biên nhận). Đã kiểm trên Kibana UAT ngày 21/10/2026 (data viewtcis-logs*, gồm các service eBerth):_idkhácevent.idở mọi bản ghi lấy mẫu, nên ở đó không bị đè. Kết quả này phụ thuộc cấu hình pipeline của từng môi trường — môi trường khác (production, cụm khác) thì kiểm lại bằng cách so_idvớievent.idcủa một bản ghi trong Discover (tab JSON), hoặc bật thử một service rồi tìm theoevent.id: thấy 2 bản ghi (started + kết thúc) là không bị đè.
Điều tra nhanh một service nghi bị treo ở Proceed()
Cấu hình đọc lúc khởi động (IOptions): đổi xong phải restart service đó. Mỗi service có appsettings riêng nên chỉ bật
cho service đang nghi ngờ.
{
"TLogSettings": {
"SlowCallThreshold": "00:00:10"
}
}
- Bước 1 — chỉ cần
SlowCallThreshold(ghi WARN nên không phải hạ min level, chi phí thấp). ThấyWARN ... still runningmà chưa có bản ghi kết thúc cùngevent.id⇒ lời gọi đã vào hàm và đang treo; kết luận "API chưa được gọi" là sai. Hàm chạy lâu hợp lệ gây ồn thì thêm vàoExcludeMethods/ExcludeClasses. - Bước 2 — nếu cần biết mọi lời gọi có vào hàm hay không, thêm
"LogInvocationStart": truevà"InvocationStartLevel": "INFO"(hoặc giữ DEBUG và hạ min level bằng Dynamic Log Level). Nặng hơn: mỗi lời gọi được log thêm một bản ghi, chỉ bật trong lúc điều tra rồi tắt. - Điều tra xong: bỏ hai khoá trên và restart.
🚀 Usage
In Program.cs, configure the IHostBuilder to use UseTAutofacLogging:
using Microsoft.Extensions.Hosting;
using System.Reflection;
var builder = WebApplication.CreateBuilder(args);
// Configure Autofac as the main DI Container and configure AOP Logging
builder.Host.UseTAutofacLogging(
scanAssemblies: new[] { Assembly.GetExecutingAssembly() }, // Scan the current Assembly
configSection: "TLogSettings:AopSettings", // Configuration section
configureOptions: options =>
{
// Can be configured via code instead of appsettings
options.DiRegistrationSuffixes.Add("Facade");
}
);
var app = builder.Build();
app.Run();
💡 Basic Example
When you have an Interface and an implementation Class with a name ending in Service (e.g., IUserService and UserService):
public interface IUserService
{
Task<User> GetUserAsync(int id);
}
// This class will be automatically registered by Autofac (due to the 'Service' suffix)
// and automatically intercepted to log Input, Output, and Exceptions.
public class UserService : IUserService
{
public async Task<User> GetUserAsync(int id)
{
return await _db.Users.FindAsync(id);
}
}
By simply configuring UseTAutofacLogging(), you no longer need to manually register builder.Services.AddScoped<IUserService, UserService>().
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. 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 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. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Autofac (>= 8.1.1)
- Autofac.Extensions.DependencyInjection (>= 10.0.0)
- Autofac.Extras.DynamicProxy (>= 7.1.0)
- Castle.Core.AsyncInterceptor (>= 2.1.0)
- Elastic.CommonSchema (>= 8.11.0)
- Microsoft.Bcl.AsyncInterfaces (>= 9.0.0)
- Microsoft.Bcl.TimeProvider (>= 9.0.0)
- Microsoft.Extensions.Configuration.Abstractions (>= 9.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 9.0.0)
- Microsoft.Extensions.DependencyInjection (>= 9.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.0)
- Microsoft.Extensions.Hosting.Abstractions (>= 9.0.0)
- Microsoft.Extensions.Logging (>= 9.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 9.0.0)
- Microsoft.Extensions.Options (>= 9.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 9.0.0)
- System.Diagnostics.DiagnosticSource (>= 9.0.0)
- System.Text.Encodings.Web (>= 9.0.0)
- System.Text.Json (>= 8.0.6)
- System.Threading.Channels (>= 8.0.0)
- TCIS.Logging (= 1.0.9)
-
net8.0
- Autofac (>= 8.1.1)
- Autofac.Extensions.DependencyInjection (>= 10.0.0)
- Autofac.Extras.DynamicProxy (>= 7.1.0)
- Castle.Core.AsyncInterceptor (>= 2.1.0)
- Elastic.CommonSchema (>= 8.11.0)
- Microsoft.Extensions.Configuration.Abstractions (>= 9.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 9.0.0)
- Microsoft.Extensions.DependencyInjection (>= 9.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.0)
- Microsoft.Extensions.Hosting.Abstractions (>= 9.0.0)
- Microsoft.Extensions.Logging (>= 9.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 9.0.0)
- Microsoft.Extensions.Options (>= 9.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 9.0.0)
- System.Diagnostics.DiagnosticSource (>= 10.0.0)
- System.Text.Encodings.Web (>= 9.0.0)
- System.Text.Json (>= 9.0.0)
- System.Threading.Channels (>= 8.0.0)
- TCIS.Logging (= 1.0.9)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on TCIS.Logging.Autofac:
| Package | Downloads |
|---|---|
|
TCIS.Pluggable.Engine.Autofac
TCIS Core Framework is an application framework for building modular, multi-tenant applications on ASP.NET Core. Autofac integration for TCIS.Pluggable.Engine |
|
|
TCIS.Logging.Hosting
One-call TCIS application logging composition, startup lifecycle and downstream failure attribution. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.9 | 0 | 11/5/2026 |
| 1.0.9-rc.2 | 0 | 11/5/2026 |
| 1.0.9-rc.1 | 44 | 11/4/2026 |
| 1.0.8 | 68 | 11/3/2026 |
| 1.0.8-rc.11 | 68 | 10/30/2026 |
| 1.0.8-rc.10 | 62 | 10/30/2026 |
| 1.0.8-rc.9 | 71 | 10/30/2026 |
| 1.0.8-rc.8 | 66 | 10/29/2026 |
| 1.0.8-rc.7 | 74 | 10/27/2026 |
| 1.0.8-rc.6 | 77 | 10/27/2026 |
| 1.0.8-rc.5 | 79 | 10/23/2026 |
| 1.0.8-rc.4 | 71 | 10/23/2026 |
| 1.0.8-rc.3 | 69 | 10/23/2026 |
| 1.0.8-rc.2 | 65 | 10/22/2026 |
| 1.0.8-rc.1 | 73 | 10/22/2026 |
| 1.0.7 | 130 | 10/22/2026 |
| 1.0.6 | 131 | 10/20/2026 |
| 1.0.6-rc.1 | 64 | 10/20/2026 |
| 1.0.5 | 140 | 10/19/2026 |
| 1.0.4 | 124 | 10/13/2026 |