using log4net; using log4net.Config; using System.IO; public class MyClass { private static readonly ILog Log = LogManager.GetLogger(typeof(MyClass)); static MyClass() { XmlConfigurator.Configure(new FileInfo("log4net.config")); } public void MyMethod() { Log.Debug("Debug message"); Log.Info("Info message"); Log.Warn("Warning message"); Log.Error("Error message"); Log.Fatal("Fatal message"); } }
using log4net; using log4net.Config; using System.IO; public class MyClass { private static readonly ILog Log = LogManager.GetLogger(typeof(MyClass)); static MyClass() { XmlConfigurator.Configure(new FileInfo("log4net.config")); } public void MyMethod(string message, int level) { switch (level) { case 1: Log.Logger.Log(typeof(MyClass), Level.Alert, message, null); break; case 2: Log.Error(message); break; case 3: Log.Warn(message); break; default: Log.Info(message); break; } } }In this example, a custom log level is used based on the input level of the MyMethod() function. The custom log level is an Alert level, which is higher than the Error log level. The Logger.Log() function is used to log messages with the custom level. The message is logged with different severity levels depending on the input level. In conclusion, ILog is a logging interface in C# used to log events and messages in an application for debugging and analyzing purposes. It is a part of the log4net library package in C#. The log4net library package provides various functionalities for logging, including logging configuration, custom log levels, and log appenders.