![]() |
VOOZH | about |
dotnet add package Oakrey.Applications.Trace --version 2.0.4
NuGet\Install-Package Oakrey.Applications.Trace -Version 2.0.4
<PackageReference Include="Oakrey.Applications.Trace" Version="2.0.4" />
<PackageVersion Include="Oakrey.Applications.Trace" Version="2.0.4" />Directory.Packages.props
<PackageReference Include="Oakrey.Applications.Trace" />Project file
paket add Oakrey.Applications.Trace --version 2.0.4
#r "nuget: Oakrey.Applications.Trace, 2.0.4"
#:package Oakrey.Applications.Trace@2.0.4
#addin nuget:?package=Oakrey.Applications.Trace&version=2.0.4Install as a Cake Addin
#tool nuget:?package=Oakrey.Applications.Trace&version=2.0.4Install as a Cake Tool
A .NET library for tracing application activities to files. Exposes a base class and interface for building custom tracers with start/stop control, real-time Rx observables for status and elapsed time, configurable file naming, and thread-safe file writing.
NuGet package ID: Oakrey.Applications.Trace
ITracer interface with StartTrace / StopTrace, Tracing state, and TracePath configurationTracerBase abstract base class handles all file I/O, timer management, and observable publishingIObservable<TracerStatus> (Stopped / Running / Paused) emitted via StatusChangedIObservable<TimeSpan> emitted every millisecond via TraceTimeChanged for live elapsed-time bindingITracerSettingsOakrey.Files.FileNameSource (supports naming policies and auto-increment)lock and MemoryPool<byte> to avoid per-write allocationsOakrey.Log for internal diagnostic logging and Oakrey.Telemetry for activity tracingIDisposable support: stopping an active trace on disposalclassDiagram
class ITracer {
+IObservable~TracerStatus~ StatusChanged
+IObservable~TimeSpan~ TraceTimeChanged
+bool Enabled
+bool FolderTraceCorrect
+bool Tracing
+string TracePath
+string TraceTime
+StartTrace()
+StopTrace()
}
class TracerBase {
#abstract string FileName
#abstract string SwName
#abstract string Extension
#abstract WriteHeader()
#WriteLine(string)
#int Incrementor
}
class ITracerSettings {
+string LastTraceFolderPath
+FileNamingPolicy TraceFileNamingPolicy
+int LastTraceFileIncrement
+string Format
}
class TracerStatus {
<<enumeration>>
Stopped
Running
Paused
}
ITracer <|.. TracerBase
TracerBase --> ITracerSettings
TracerBase --> TracerStatus
| File | Purpose |
|---|---|
ITracer.cs |
Public contract for all tracer implementations |
TracerBase.cs |
Abstract base with file I/O, timer, and observable wiring |
ITracerSettings.cs |
Settings contract injected into TracerBase |
TracerStatus.cs |
Enum: Stopped, Running, Paused |
Oakrey.Files 3.0.0Oakrey.Log 2.0.0Oakrey.Telemetry 2.0.1System.Reactive 6.1.0NuGet Package Manager
Oakrey.Applications.Trace and click Install..NET CLI
dotnet add package Oakrey.Applications.Trace
Package Manager Console
Install-Package Oakrey.Applications.Trace
Implement ITracerSettings to provide trace configuration. All properties must be persisted by the caller (e.g. in user settings or a configuration file):
public class MyTracerSettings : ITracerSettings
{
public string LastTraceFolderPath { get; set; } = @"C:\Traces";
public FileNamingPolicy TraceFileNamingPolicy { get; set; } = FileNamingPolicy.DateTimePrefix;
public int LastTraceFileIncrement { get; set; } = 0;
public string Format { get; set; } = "yyyy-MM-dd";
}
Extend TracerBase to define the file name, application name, extension, and the custom header written at the top of every trace file:
public class AppTracer : TracerBase, ITracer
{
public AppTracer(ITracerSettings settings) : base(settings) { }
protected override string FileName => "AppTrace";
protected override string SwName => "MyApplication";
protected override string Extension => "log";
protected override void WriteHeader()
{
WriteLine("=== MyApplication trace ===");
WriteLine($"Started: {DateTime.Now}");
}
// Expose StartTrace publicly (protected in base)
public new void StartTrace() => base.StartTrace();
}
Subscribe to observables to drive UI or diagnostic output:
AppTracer tracer = new(new MyTracerSettings());
tracer.StatusChanged.Subscribe(status =>
Console.WriteLine($"Tracer status: {status}"));
tracer.TraceTimeChanged.Subscribe(elapsed =>
Console.WriteLine($"Elapsed: {elapsed}"));
tracer.StartTrace();
// ... write lines via WriteLine inside the tracer
tracer.StopTrace();
TracerBase acquires a Lock on every WriteLine call. Writers on background threads are safe without additional synchronization.Paused is defined in TracerStatus but is not set by TracerBase itself. Custom subclasses can publish it via the inherited status subject.StopTrace if tracing is active, ensuring the trace footer is written and the file is closed cleanly.MIT - Copyright (c) Oakrey 2016-present
Contributions are welcome! Feel free to open issues or submit pull requests to improve the package.
This project is licensed under the MIT License. See the LICENSE file for details.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.