kolappannathan / simple-csv-logger

This is a simple csv file logger for logging errors in a c# application.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Simple CSV Logger

The repository is archived for reference. The package is no longer maintained.

Targets .Net standard 2.0 GitHub

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.

Downloads: Nuget

Usage

  1. Install the nuget package.
  2. Create an instance for nk.logger.csv.Logger in your base class.
  3. Edit the configuration according to your application needs.
  4. Create wrapper functions for the functions you need from csv.logger.
  5. Inherit this base class in your other classes.

Example

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]
    }
}

About

This is a simple csv file logger for logging errors in a c# application.

License:MIT License


Languages

Language:C# 100.0%