Coder Social home page Coder Social logo

kaliko.logger's Introduction

Kaliko.Logger

A light weight yet competent logger for .NET with configurable output modules, such as log file, e-mail and debug log. Easy to add your own output module if needed.

##Usage

In your configuration file (web.config for web applications or app.config for applications) register a new section called loggers:

  <configSections>
    <section name="loggers" type="Kaliko.Configuration.LoggersSection, Kaliko.Logger" />
  </configSections>

Add a new section in your configuration and add one or more loggers to it:

  <loggers>
    <fileLogger filename="c:\temp\log%yyyy%mm%dd.txt" treshold="Warning" />
    <mailLogger from="[email protected]" to="[email protected]" subject="An error has occured" treshold="Major" />
    <debugLogger treshold="Info" />
  </loggers>

Each logger has a treshold (should have been "threshold") value that sets the lower bound of which items that should be logged through that logger.

In the example above all the different loggers are set up (fileLogger, mailLogger and debugLogger) but with different thresholds. That means that a log item of the severity "Info" only will be written to the debugLogger but an item of the severity "Critical" will be written to all.

The severity levels are (in ascending order): NotSet, Info, Warning, Minor, Major and Critical

To write a string to the log:

using Kaliko;

// ...

Logger.Write("Just some information", Logger.Severity.Info);

To write an exception to the log:

using Kaliko;

// ...
try {
  // ...
}
catch (Exception exception) {
  Logger.Write(exception , Logger.Severity.Major);
}

Loggers

FileLogger

The FileLogger requires a filename to be specified that points out which file the logger should write to. It's either specified with an absolute path like "c:\temp\mylog.txt" or a relative path based on from where the application is executed. In order to use the App_data folder in a website project, the shortcut |datadirectory| could be used (such as "|datadirectory|mylog.txt").

To use rolling log files the following variables can be used: %yyyy = Year %mm = Month %dd = Day of month

The following will write to a log file for each month in the App_data folder: "|datadirectory|mylog-%yyyy-%mm.txt"

MailLogger

Sends the log item as an email to the specified recipient. Needs both a from and a to address to be specified as well as a subject to be used for the mails.

DebugLogger

Writes the log item to the debug view. Usable together with a tool like https://technet.microsoft.com/en-us/sysinternals/bb896647.aspx

kaliko.logger's People

Contributors

fschultz avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

kaliko.logger's Issues

Documentation?

I cant find documentation anywhere. Just by reading some of the source it looks like I have to add the config information into an App.Config or something?

How to configure the loggers in the configurationfile?

I am trying to use the logger and I have not figures out how to configure the loggers in the configuration file. What is the xml configuraiton like for ConfigurationManager.GetSection("loggers") to correctly convert into LoggersSection?

I tried to reverse engineer it. Not sure if this is the intended setup in configuration file.

  <loggers>
    <fileLogger filename="trxyLogger" treshold="1"/>
    <mailLogger from="[email protected]" to="[email protected]" subject="trxy error" treshold="5"/>
    <debugLogger treshold="3"/>
  </loggers>

Tried adding the following element in the config section.

   <section name="loggers" type="Kaliko.Configuration.LoggersSection, Kaliko.Logger" />

with the following section

  <loggers>
    <fileLogger filename="c:\logFile.txt" treshold="NotSpecified" />
  </loggers>

and I get a Configuration System Failed to Initialized error with the message Unrecognized configuration section loggers.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.