Log.to.Text.File 3.0.4

There is a newer version of this package available.
See the version list below for details.
dotnet add package Log.to.Text.File --version 3.0.4                
NuGet\Install-Package Log.to.Text.File -Version 3.0.4                
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="Log.to.Text.File" Version="3.0.4" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Log.to.Text.File --version 3.0.4                
#r "nuget: Log.to.Text.File, 3.0.4"                
#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 Log.to.Text.File as a Cake Addin
#addin nuget:?package=Log.to.Text.File&version=3.0.4

// Install Log.to.Text.File as a Cake Tool
#tool nuget:?package=Log.to.Text.File&version=3.0.4                

About

Helper class which writes to txt file. Useful when running scheduled scripts and you want to have something to double check what was done and when.

Runs with netcoreapp3.1, net5.0 and net6.0.

Usage

Initiate logger like this (uses System.AppDomain.CurrentDomain.BaseDirectory to determine the destination directory):

var log = new SessionLog();

or define your own destination like this:

var log = new SessionLog(@"C:\Users\USER\Desktop");

You can log text like this:

log.Write("Hello World!");

Or retrieve the path of the log file like this:

string publicProperty = log.FilePath;

Example

using System;
using Log.to.Text.File;

namespace Example
{
    class Program
    {
        static void Main(string[] args)
        {
            var log = new SessionLog(@"C:\Users\USER\Desktop");

            try
            {
                log.Write("I declared an array");
                int[] myArray = new int[1];
                log.Write("I set 99 to second index");
                myArray[1] = 99;
            }
            catch (System.Exception e)
            {
                log.Write(e);
            }
        }
    }
}

Session_Log_07122021_125838.txt

12/7/2021 12:58:38 PM >> I declared an array
12/7/2021 12:58:38 PM >> I set 99 to second index
12/7/2021 12:58:38 PM >> EXCEPTION MESSAGE: Index was outside the bounds of the array.
12/7/2021 12:58:38 PM >> STACK TRACE:    at Log_to_TXT.Program.Main(String[] args) in C:\Users\USER\source\repos\Log_to_TXT\Log_to_TXT\Program.cs:line 15
Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 is compatible.  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 was computed.  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. 
.NET Core netcoreapp3.1 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
4.0.0 893 8/12/2022
3.0.4 791 5/4/2022

Repacked for .netcore3.1, net5 and net6