This is a simple logger for logging errors in a c# application. But instead of writing the logs to a txt file this logger writes them into a CSV file.
- Install the nuget package.
- Create an instance for
nk.logger.csv.Logger
in your base class. - Edit the configuration according to your application needs.
- Create wrapper functions for the functions you need from csv.logger.
- Inherit this base class in your other classes.
Below is a sample base class with configurations,
using System;
namespace Core.Lib
{
public class Logger
{
private nk.logger.csv.Logger csvLogger;
public Logger(string dateFormat, string fileName, string relativePath = "", char replacementValue = ';')
{
var config = new nk.logger.csv.LoggerConfig();
// adding configuration
config.SetDateTimeFormat(dateFormat)
.SetFileName(fileName)
.SetRelativePath(relativePath)
.SetReplacementValue(replacementValue);
csvLogger = new nk.logger.csv.Logger(config);
}
#region [Public Logger functions]
public void Error(Exception ex) => csvLogger.Error(ex);
public void Fatal(Exception ex) => csvLogger.Fatal(ex);
public void Debug(string text) => csvLogger.Debug(text);
public void Error(string text) => csvLogger.Error(text);
public void Fatal(string text) => csvLogger.Fatal(text);
#endregion [Public Logger functions]
}
}