Table of Contents

Class FileLogger

Namespace
VpnHood.Net.Toolkit.Logging
Assembly
VpnHood.Net.Toolkit.dll

Provides the process's log file: opened at each start request, in place of what it had or after it, and closed at stop; closed, it takes nothing.

public sealed class FileLogger : ILogger
Inheritance
FileLogger
Implements
Inherited Members

Constructors

FileLogger(string)

Provides the process's log file: opened at each start request, in place of what it had or after it, and closed at stop; closed, it takes nothing.

public FileLogger(string filePath)

Parameters

filePath string

The file's path.

Properties

AutoFlush

Gets or sets a value indicating whether every line is flushed as it comes; otherwise, lines are buffered, and flushed at an error either way.

public bool AutoFlush { get; set; }

Property Value

bool

FilePath

Gets the file's path.

public string FilePath { get; }

Property Value

string

IsOpen

Gets a value indicating whether the file is open.

public bool IsOpen { get; }

Property Value

bool

Methods

BeginScope<TState>(TState)

Begins a logical operation scope.

public IDisposable? BeginScope<TState>(TState state) where TState : notnull

Parameters

state TState

The identifier for the scope.

Returns

IDisposable

An IDisposable that ends the logical operation scope on dispose.

Type Parameters

TState

The type of the state to begin scope for.

Remarks

It keeps no scopes: it returns null.

Close()

Closes the file. A failure to flush what is buffered, as on a full disk, is written to the console instead of thrown, and the logger is closed all the same.

public void Close()

IsEnabled(LogLevel)

Checks if the given logLevel is enabled.

public bool IsEnabled(LogLevel logLevel)

Parameters

logLevel LogLevel

Level to be checked.

Returns

bool

true if enabled.

Remarks

It is true while the file is open.

Log<TState>(LogLevel, EventId, TState, Exception?, Func<TState, Exception?, string>)

Writes a log entry.

public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter)

Parameters

logLevel LogLevel

Entry will be written on this level.

eventId EventId

Id of the event.

state TState

The entry to be written. Can be also an object.

exception Exception

The exception related to this entry.

formatter Func<TState, Exception, string>

Function to create a string message of the state and exception.

Type Parameters

TState

The type of the object to be written.

Remarks

It writes the formatted message as a line; a failure goes to the console.

Open(bool)

Opens the file, closing it first when it is open, as Close() does; others may read it meanwhile.

public void Open(bool deleteOld)

Parameters

deleteOld bool

true to start the file afresh; false to append.

Exceptions

IOException

The file cannot be opened or deleted.

UnauthorizedAccessException

The process may not write the file.

ArgumentException

The file's path is empty or not valid.