FileLogger

FileLogger class

Represents a logger that logs events and errors to a local file.

public class FileLogger : ILogger

Constructors

Name Description
FileLogger(string, double) Initializes a new instance of the FileLogger class.

Properties

Name Description
FilePath { get; } Gets the log file path.
MaxSize { get; } Gets the maximum size of the log file in megabytes.

Methods

Name Description
Error(string) Logs an error that occurred in the index.
Trace(string) Logs an event that occurred in the index.

Remarks

A message that cannot be written, for example because the folder of the log file cannot be created or the file is locked by another process, is lost: an error of logging never stops the operation that is logged. When the file reaches its maximum size, its oldest messages are deleted, and the newest messages that take half of the maximum size are kept. A file that cannot be shortened at that moment, for example because another process has it open for writing, is shortened later; the message is written anyway. Several loggers of a process can write the same file.

Learn more

Examples

The example demonstrates a typical usage of the class.

string indexFolder = @"c:\MyIndex\";
string documentsFolder = @"c:\MyDocuments\";
string query = "Einstein";
string logPath = @"c:\Log.txt";

IndexSettings settings = new IndexSettings();
settings.Logger = new FileLogger(logPath, 4.0); // Specifying the path to the log file and a maximum length of 4 MB

Index index = new Index(indexFolder, settings); // Creating an index in the specified folder

index.Add(documentsFolder); // Indexing documents from the specified folder

SearchResult result = index.Search(query); // Search in index

See Also