원클릭으로
logging
UTF-8 file logging with automatic date-based filenames and thread-safe operations for RocsMiddleware services
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
메뉴
UTF-8 file logging with automatic date-based filenames and thread-safe operations for RocsMiddleware services
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
SOC 직업 분류 기준
Anthropic API rate limit handling - retry logic, backoff, throttling for batch workloads against Claude models
Use when building an automated test → issue → fix loop with Claude Code and GitHub issues — overnight auto-fixing, regression loops, self-healing CI.
Use when creating, editing, publishing, or deleting posts on Cyril's Workshop blog or the steponnopets.net devblog.
Use when writing or contributing a boofuzz network-protocol fuzzer in this repo — layout, formatting rules, and reading results.
Use when a task needs real-time control of a connected browser via the Browser Bridge Broker — submit JS jobs over HTTP that browsers eval and return.
Use when training a character LoRA (Chroma/Flux or Pony/SDXL) on a RunPod GPU and wiring it into the ComfyUI + pony_web render stack.
| name | Logging |
| description | UTF-8 file logging with automatic date-based filenames and thread-safe operations for RocsMiddleware services |
When helping users implement logging in RocsMiddleware services, follow these guidelines:
Command-Line Option: Always include --log-dir parameter for specifying log directory path
UTF-8 Encoding: All log files must use UTF-8 encoding without BOM
Automatic Filename Pattern: Use {ProgramName}_YYYY_MM_DD.log format with automatic date rotation
Directory Path Handling: Smart detection - if path has no extension or ends with separator, treat as directory and use directory name as base filename
Error Handling: Include console output before logger initialization since logger may fail. Always check if _logger is null in exception handlers.
Log Levels: Use LogLevel.Debug with --debug flag, default to LogLevel.Information
Thread Safety: The UTF8Writer uses locking for concurrent writes
Utf8LoggingExtensions.cs: Copy the reference implementation to project's Services/ directory - provides UTF8Writer, UTF8LoggerProvider, UTF8Logger, and helper methods
User: Help me add logging to my RocsMiddleware service
Claude: I'll set up the standard UTF-8 file logging pattern:
- Add --log-dir command-line option
- Copy Utf8LoggingExtensions.cs to Services/
- Initialize logger with automatic date-based filename
- Add console output before logger initialization for debugging
[Provides implementation using the Logger Initialization pattern from reference material below]
User: Why isn't my log file being created when I specify --log-dir?
Claude: Let me check the directory path handling. The logger should:
- Detect if path is a directory (no extension or ends with separator)
- Use directory name as base filename
- Add date string and .log extension automatically
Common issue: Old Utf8LoggingExtensions.cs without directory detection logic.
Solution: Copy the updated version from skills folder.
[Provides directory detection implementation from reference material below]
User: My program just prints "Error" with no details
Claude: This happens when an exception occurs before logger initialization. I'll add:
- Console.WriteLine at key points (startup, before logger init, after logger init)
- Null check on _logger in exception handler
- Fallback to console output if logger is null
[Provides error handling pattern from reference material below]
The sections below contain proven working code from RocsMiddleware services that the examples above reference.
Reference Files in This Folder:
Utf8LoggingExtensions.cs - Complete UTF-8 logger implementation (copy to Services/)All RocsMiddleware services use a consistent logging approach:
--log-dir parameter specifies the directory path{ProgramName}_YYYY_MM_DD.log[Option("log-dir", Required = false, HelpText = "Directory for log files")]
public string? LogDir { get; set; }
// Initialize logger with optional log directory
var logLevel = options.Debug ? LogLevel.Debug : LogLevel.Information;
_logger = {Namespace}.Services.Utf8LoggingExtensions.CreateUtf8Logger(
"{ProgramName}",
logLevel,
options.LogDir);
dotnet run -- --log-dir "C:\RI Services\Logs\MyProgram" --other-options
This creates: C:\RI Services\Logs\MyProgram\MyProgram_2025_10_16.log
The UTF8Writer.Init() method automatically detects directory paths and creates properly named log files:
.log extension is added automaticallyYYYY_MM_DD is inserted before the extensionInput --log-dir | Output Log File |
|---|---|
C:\Logs\MyProgram | C:\Logs\MyProgram\MyProgram_2025_10_16.log |
C:\Logs\MyProgram\ | C:\Logs\MyProgram\MyProgram_2025_10_16.log |
C:\Logs\MyProgram\custom.log | C:\Logs\MyProgram\custom_2025_10_16.log |
C:\Logs\MyProgram\custom | C:\Logs\MyProgram\custom_2025_10_16.log (adds .log extension) |
All services include a Services/Utf8LoggingExtensions.cs file that provides:
UTF8Writer class: Low-level UTF-8 file writer with thread-safe lockingUTF8LoggerProvider: Custom logger provider for Microsoft.Extensions.LoggingUTF8Logger: ILogger implementation that writes to UTF-8 filesCreateUtf8Logger(): Helper method to create a configured logger instanceConfigureUtf8Logging(): Extension method for ILoggingBuilderSince the logger may fail to initialize, always include console output for early errors:
public static async Task Main(string[] args)
{
try
{
Console.WriteLine("{ProgramName} starting...");
// Parse command line
CommandLineOptions? options = null;
Parser.Default.ParseArguments<CommandLineOptions>(args)
.WithParsed(opts => options = opts)
.WithNotParsed(errors =>
{
Console.WriteLine("Failed to parse command line arguments");
Environment.Exit(1);
});
if (options == null)
{
Console.WriteLine("Failed to parse command line options");
Environment.Exit(1);
return;
}
Console.WriteLine($"Initializing logger with log-dir: {options.LogDir ?? "(null)"}");
// Initialize logger
_logger = {Namespace}.Services.Utf8LoggingExtensions.CreateUtf8Logger(
"{ProgramName}",
options.Debug ? LogLevel.Debug : LogLevel.Information,
options.LogDir);
Console.WriteLine("Logger initialized");
_logger.LogInformation("{ProgramName} starting");
// ... rest of program
}
catch (Exception ex)
{
if (_logger != null)
{
_logger.LogError(ex, "{ProgramName} failed: {Message}", ex.Message);
}
else
{
Console.WriteLine($"{ProgramName} failed: {ex.Message}");
Console.WriteLine(ex.StackTrace);
}
Environment.Exit(1);
}
}
Standard log levels used across all services:
LogLevel.Debug: Verbose diagnostic information (use --debug flag)LogLevel.Information: General informational messages (default)LogLevel.Warning: Warning messages for non-critical issuesLogLevel.Error: Error messages for failuresdotnet run -- --pqdir "R:\Outputs\Parquets\poller" --pg "R:\JsonParams\x3rocs_db.json" --log-dir "C:\RI Services\Logs\PriceExtractor" --full
Creates: C:\RI Services\Logs\PriceExtractor\PriceExtractor_2025_10_16.log
dotnet run -- --pg "R:/JsonParams/x3rocs_db.json" --log-dir "R:/Logs/PriceDiscounter" --elastic https://rocs-stage-es.ramsden-international.com/ --debug --sphkey1 425073
Creates: R:/Logs/PriceDiscounter/PriceDiscounter_2025_10_16.log
{ProgramName}_YYYY_MM_DD.log pattern--log-dir (console only)Symptom: Program runs but no log file appears in the specified directory.
Causes:
Utf8LoggingExtensions.cs without directory path handlingSolution:
Utf8LoggingExtensions.cs from this skills folder to your project's Services/ directoryUTF8Writer.Init() method includes directory detection logicSymptom: Program outputs just "Error" with no stack trace or details.
Causes:
Solution:
_logger is null before using itUtf8LoggingExtensions.cs: Reference implementation included in this folder - copy to your project's Services/ directoryCommandLineParser library--log-dir is not specified, logging goes to console only (if enabled)