# ThrottledLogging
**Repository Path**: coldhighsun/ThrottledLogging
## Basic Information
- **Project Name**: ThrottledLogging
- **Description**: 基于时间间隔的 Microsoft.Extensions.Logging 日志限流器,可按 key 抑制重复日志,并在恢复输出时报告被抑制的条数。
- **Primary Language**: C#
- **License**: MIT
- **Default Branch**: main
- **Homepage**: https://github.com/coldhighsun/ThrottledLogging
- **GVP Project**: No
## Statistics
- **Stars**: 1
- **Forks**: 0
- **Created**: 2026-04-11
- **Last Updated**: 2026-11-22
## Categories & Tags
**Categories**: Uncategorized
**Tags**: 日志, log, logging, throttle, rate-limit
## README
# ThrottledLogging
[](https://github.com/coldhighsun/ThrottledLogging/actions/workflows/ci.yml)
[](https://www.nuget.org/packages/ThrottledLogging)
[](https://www.nuget.org/packages/ThrottledLogging)
[](https://github.com/coldhighsun/ThrottledLogging/releases/latest)
[](https://github.com/coldhighsun/ThrottledLogging/releases)
[](https://github.com/coldhighsun/ThrottledLogging/issues)
[](https://github.com/coldhighsun/ThrottledLogging/pulls)
[](https://github.com/coldhighsun/ThrottledLogging/commits/main)
[](https://github.com/coldhighsun/ThrottledLogging/stargazers)
[](https://github.com/coldhighsun/ThrottledLogging/blob/main/LICENSE)
[](https://dotnet.microsoft.com/)
[English](https://github.com/coldhighsun/ThrottledLogging/blob/main/README.md) | 简体中文 | [繁體中文](https://github.com/coldhighsun/ThrottledLogging/blob/main/README.zh-TW.md)
---
基于时间间隔的 `Microsoft.Extensions.Logging` 日志限流器,可按 key 抑制重复日志,并在恢复输出时报告被抑制的条数。
## 项目结构
| 项目 | 说明 |
|---|---|
| `src/ThrottledLogging` | NuGet 库 |
| `examples/GettingStarted` | 控制台示例,涵盖所有功能 |
## 安装
```
dotnet add package ThrottledLogging
```
## 用法
在任意 `ILogger` 上调用限流扩展方法。每次调用需传入一个 **key**(用于标识被限流的日志消息)和一个 **interval**(两次输出之间的最短间隔)。
```csharp
// "disk-full" 这个 key 每分钟最多输出一次。
// 抑制后下次恢复输出时,会自动追加"(N messages suppressed)"。
logger.LogWarningThrottled("disk-full", TimeSpan.FromMinutes(1), "Disk usage is above {Percent}%", usage);
```
可用方法与标准 `ILogger` API 一一对应:
- `LogTraceThrottled`
- `LogDebugThrottled`
- `LogInformationThrottled`
- `LogWarningThrottled`
- `LogErrorThrottled`
- `LogCriticalThrottled`
每个方法的签名为 `(string key, TimeSpan interval, string? messageTemplate, params ReadOnlySpan