Click here to Skip to main content
15,894,630 members
Articles / Desktop Programming / Win32

.NET File Logging Library

Rate me:
Please Sign up or sign in to vote.
2.33/5 (6 votes)
17 Apr 2008CPOL1 min read 42.9K   434   18  
A simple yet useful library for file based logging implemented in .NET using C#
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Logger;

namespace LogClient
{
    class Program
    {
        static void Main(string[] args)
        {
            TestLogger();
        }

        static void TestLogger()
        {
            CLogger TestLogger = new CLogger();            

            TestLogger.Initialize("C:", "Test.log"); // Specify location and log file name
            //TestLogger.Initialize("C:", "Test.log", 50); // Set log file size as well

            // Logging just message strings with different severity levels
            TestLogger.LogInformation("My First Test Log Message");
            TestLogger.LogWarning("My First Test Log Message");
            TestLogger.LogError("My First Test Log Message");

            // Logging error codes and message strings with different severity levels
            TestLogger.LogInformation(1005, "My First Test Log Message");
            TestLogger.LogWarning(1005, "My First Test Log Message");
            TestLogger.LogError(1005, "My First Test Log Message");

            // Logging class name, method name and message strings with different severity levels
            TestLogger.LogInformation("LogClient", "TestLog", "My First Test Log Message");
            TestLogger.LogWarning("LogClient", "TestLog", "My First Test Log Message");
            TestLogger.LogError("LogClient", "TestLog", "My First Test Log Message");

            TestLogger.Terminate();
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions