CSVMetricsLogger 1.1.0

dotnet add package CSVMetricsLogger --version 1.1.0
NuGet\Install-Package CSVMetricsLogger -Version 1.1.0
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="CSVMetricsLogger" Version="1.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CSVMetricsLogger --version 1.1.0
#r "nuget: CSVMetricsLogger, 1.1.0"
#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.
// Install CSVMetricsLogger as a Cake Addin
#addin nuget:?package=CSVMetricsLogger&version=1.1.0

// Install CSVMetricsLogger as a Cake Tool
#tool nuget:?package=CSVMetricsLogger&version=1.1.0

CSV Metrics Logger

This is a simple CSV metrics logger that logs metrics to a CSV file. It is designed to be used in a multithreaded environment. Here is an example of how to use it:

using CSV_Metrics_Logger;

[CSVRecord]
public readonly partial record struct TestData(string Name, sbyte Age);

List<TestData> testData =
[
    new TestData("Name 1", 14),
    new TestData("Name 2", 25),
    new TestData("Name 3", 36),
    new TestData("Name 4", 47),
    new TestData("Name 5", 58),
];

var filename = Path.GetTempFileName();
await using var storage = CSVStorage<TestData>.Create(filename);

foreach (var data in testData)
    storage.Write(data);

You might use storage.Write from multiple threads. The logger will handle the synchronization for you.

CSV Metrics Logger uses a source generator. You need to use the following NuGet packages:

<PackageReference Include="CSVMetricsLoggerGenerator" Version="1.1.0" />
<PackageReference Include="CSVMetricsLogger" Version="1.1.0" />

Your data must be modeled as a structure; classes are not supported. It does not matter if you are using a (readonly) record struct or a regular struct. The only requirement is that the struct must be a partial struct. The source generator will generate the missing part of the struct for you. Each public property will be used as a column in the CSV file. The property type can be any type, as long as it supports the ToString() method.

Additionally, you can use generic type parameters in your struct, as long as there is a suitable ToString() overload. Here is an example:

using CSV_Metrics_Logger;

[CSVRecord]
public readonly partial record struct GenericTestData<TNum>(string Name, sbyte Age, TNum Measure) where TNum : IFloatingPointIeee754<TNum>;

List<TestData> testData =
[
    new TestData<float>("Name 1", 14, 47.53f),
    new TestData<float>("Name 2", 25, 19.84f),
    new TestData<float>("Name 3", 36, 38.78f),
    new TestData<float>("Name 4", 47, 17.25f),
    new TestData<float>("Name 5", 58, 73.89f),
];

var filename = Path.GetTempFileName();
await using var storage = CSVStorage<TestData<float>>.Create(filename);

foreach (var data in testData)
    storage.Write(data);

For each data structure, you create a CSVStorage instance. The CSVStorage instance is a disposable object. You must dispose of it when you are done with it. When the CSV file already exists, the CSVStorage object will append data to the existing file; the header will not be written again.

Product Compatible and additional computed target framework versions.
.NET 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

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.1.0 69 5/21/2024
1.0.0 88 5/5/2024