- ADD reference to Log4net.dll to our console Service host project (we application entry point)
Add the following line to the above project's AssemblyInfo.cs file (allows a custom log4net config file to be specified, W Hich log4net'll "watch" for updates. Quick, but maybe a bit dirty.)
[assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.config", Watch = true)]
- LOG 4 net Config
[Assembly:log4net. Config.xmlconfigurator (Watch=true)]
ADD log4net.config file to console project and copy it to the output directory (file properties: "Copy to output directory ")
- ADD Log4net.dll reference to all projects where you require logging
Declare the logger as private static member of the classes where you need logging:
log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
Log where required:
Logger.Info("Starting console service host");
Using log4net on my project within a self-hosted WCF application Z