Log4Net Example in C# Console Application

[code lang=”c#”]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using log4net;
using log4net.Config;
using System.IO;

namespace HowToSolveNow
class Program
private static ILog logger;

#region Logging Functions
static void LogString(string stringToLog)

private static void InitializeLogger()
if (log4net.LogManager.GetCurrentLoggers().Length == 0)
string path=AppDomain.CurrentDomain.BaseDirectory.ToString();
string configFile = path + “log4net.config”;
log4net.Config.XmlConfigurator.Configure(new FileInfo(configFile));
logger = log4net.LogManager.GetLogger(typeof(Program));
logger.Info(“Begin processing.”);

static void Main(string[] args)
LogString(“Sample Text for Log File”);

[code lang=”xml”]


About the author

Janaki(http://mjanaki.com) - A Software developer with 9+ years of experience in multiple technology projects across web, mobile, and cloud applications with expertise in PHP, C#, MySQL, Web services and open source platforms.

Similar Posts

Sample nginx vhsot config file
Uninstall MySql on a Mac OS X
VMWare shared folder as apache vhost

Leave a reply


Eye Test: * Time limit is exhausted. Please reload CAPTCHA.