1. Tom Schreiber
  2. ProgramLogger

Overview

HTTPS SSH

Codebit ProgramLogger

http://codebit.de/programlogger

This small C# Class can be used to create a simple Log-File in your .NET-program. All you have to do is providing the filename of your Log-File. Now you can easily write error- or info-messages or just plain text to this file with a short call. Timestamps are also supported.

Author

Tom Schreiber tom@codebit.de

License

New BSD License

Usage & Example

see project "TestLogger"

using System;
using System.Collections.Generic;
using System.Text;
// --> Use the namespace 'Codebit.ProgramLogger'
using Codebit.ProgramLogger;

namespace TestLogger
{
    class Program
    {
        static void Main(string[] args)
        {
            // Init new TXT-log
            LogFile Log = new LogFile("test.log", false, LogFile.LogType.TXT, LogFile.LogLevel.All);

            // Write some text to the log
            Log.LogRaw("ProgramLogger " + LogFile.VERSION + "(Build: " + LogFile.BUILD + ") is loaded");
            Log.Log("START LOG", LogFile.LogLevel.Debug);
            Log.Log("Log-level is set to: " + Log.CurrentLogLevel, LogFile.LogLevel.Debug);
            Log.Log("Log-Type is " + Log.CurrentLogType, LogFile.LogLevel.Debug);
            Log.Log("LogText started", LogFile.LogLevel.Info);
            Log.Log("Write Log with default log-level");
            Log.DefaultLogLevel = LogFile.LogLevel.User1;
            Log.Log("Change default log-level to USER1");
            Log.Log("An fake-error occured ;)", LogFile.LogLevel.Error);
            Log.Log("CLOSE LOG", LogFile.LogLevel.Debug);

            /* ------------------------------------------------------------------------ */

            // Init new HTML-log, write only Debug and Error
            // (if you use this constructor, the log-file will be opened automatically)
            Log = new LogFile("test.log.html", false, LogFile.LogType.XHTML_Plain,
                LogFile.LogLevel.Debug | LogFile.LogLevel.Error, "TestLOG " + DateTime.Today.ToShortDateString());

            // Write some text to the log
            Log.LogRaw("<strong>ProgramLogger " + LogFile.VERSION + "(Build: " + LogFile.BUILD + ") is loaded</strong><br/>");
            Log.Log("START LOG", LogFile.LogLevel.Debug);
            Log.Log("Log-level is set to: " + Log.CurrentLogLevel, LogFile.LogLevel.Debug);
            Log.Log("Log-Type is " + Log.CurrentLogType, LogFile.LogLevel.Debug);
            Log.Log("LogText started", LogFile.LogLevel.Info); //you shouldn't see this in the log
            Log.Log("An fake-error occured ;)", LogFile.LogLevel.Error);
            Log.Log("CLOSE LOG", LogFile.LogLevel.Debug);

            // write footer for a valid xhtml-file
            Log.WriteFooter();
        }
    }
}