Skip to content

kolappannathan/simple-csv-logger

main
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
src
 
 
 
 
 
 
 
 
 
 

Simple CSV Logger

Targets .Net standard 2.0 GitHub GitHub Workflow Status GitHub Workflow Status

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.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages