Look at the following points
- Create a new project (I created a Console Application).
- Add NuGet package Castle.Core, Castle.Windsor and Log4Net.
- Castle.Core: Allow we to use Proxy
For example, NHibernate, an object/relational mapper uses DynamicProxy to provide lazy loading of data without the domain model classes being aware of this functionality.
- Castle.Widsor: IoC (Inversion of control container).
- Log4net: Lib to log our application.


- Implementing a simple calculator to logger their operations:
- public interface ICalculator
- {
- double Add(double x, double y);
- double Divide(double x, double y);
- }
- public class Calculator: ICalculator
- {
- public double Add(double x, double y)
- {
- return x + y;
- }
- public double Divide(double x, double y)
- {
- return x / y;
- }
- }
- Now we can proceed to coding our logger. We want to log every call function including their parameters and the return value.
- Let’s create a simple Class Calculator to be logged as follows.
- Now we need to configure log4net,
Open the AssemblyInfo.cs and insert the follow line:
[assembly: log4net.Config.XmlConfigurator(Watch = true)]
Configure the application config (app.config) as follows:- <?xml version="1.0" encoding="utf-8" ?>
- <configuration>
- <configSections>
- <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" /> </configSections>
- <startup>
- <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /> </startup>
- <log4net>
- <appender name="MyLogger" type="log4net.Appender.RollingFileAppender">
- <file type="log4net.Util.PatternString" value="MyLog.txt" />
- <appendToFile value="true" />
- <rollingStyle value="Size" />
- <maxSizeRollBackups value="20" />
- <maximumFileSize value="1000KB" />
- <layout type="log4net.Layout.PatternLayout">
- <param name="ConversionPattern" value="%date [%thread] %-5level %logger [%ndc] - %message%newline" /> </layout>
- </appender>
- <root>
- <level value="DEBUG" />
- <appender-ref ref="MyLogger" /> </root>
- </log4net>
- </configuration>

Mukesh KumarPosted Oct 30, 2015, 2:13 AM
Thanks for your sharing
Harshad PansuriyaPosted Oct 30, 2015, 1:38 AM
Nice one
Gowtham KPosted Oct 29, 2015, 1:36 PM
Good One
André de Mattos FerrazPosted Oct 29, 2015, 7:47 AM
thank you!
Sibeesh VenuPosted Oct 29, 2015, 1:34 AM
Nice Share