Configuring Log4Net in Web Applications

Log4Net is a logging tool for .NET.

In this article I will be showing the basic steps of configuring log4Net in your web application.

Following are the steps to implement log4net in your applications:

Step 1 :

In the web.config file add the following xml node :

<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
</configSections>
<log4net>
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="TestLog.txt"/>
<appendToFile value="true"/>
<rollingStyle value="Composite"/>
<datePattern value="yyyyMMdd"/>
<maxSizeRollBackups value="10"/>
<maximumFileSize value="10MB"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="[%d{yyyy-MM-dd HH:mm:ss}] [%p] [%c:%L] - %m%n"/>
</layout>
</appender>
<root>
<level value="DEBUG"/>
<appender-ref ref="RollingLogFileAppender"/>
</root>
</log4net>

“<file value=TestLog.txt/>”  specifies the name of the file where the errors/warnings will be logged.

Step 2 :

Add the reference of the log4net to the project.I have attached the log4net .dll hereby.

Download the file from here and rename it as log4net.dll.

Step 3:

In the global.asax file add the following namespaces

using log4net;
using log4net.Config;
using log4net.Repository;
using log4net.Repository.Hierarchy;

In the Application_Start Method of Global.asax.cs page add the below code:

protected void Application_Start(object sender, EventArgs e)
{
XmlConfigurator.Configure();
}

Step 4:

Now add the following code to whichever page you want to log the exception using log4net:

private static readonly ILog logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

Step 5:

Now in the catch() section of the method you can add the following line of code:

logger.Error(ex.Message);

There are different logging levels, which can be called in the code. They are as follows:

  • OFF
  • FATAL
  • ERROR
  • WARN
  • INFO
  • DEBUG
  • ALL

This is how you can successfully configure log4Net in your web application.

# Note:

In order to put OFF the log4net functionality, you can just add the following line to the web.config:

<log4net></pre>
<log4net threshold="OFF" />
<appender>.....

[/sourcecode]Let me know if you face any further issue on this.

Configuration Of WPFCAB Source Code for CCA R1 on CRM 4.0

The Customer Care Accelerator (CCA) R1 for Microsoft Dynamics CRM4.0 focuses on delivering contact center enabling functionality, such as the ability to create unique data elements from disparate line of business applications and displaying it in a single user interface.

The accelerator in conjunction with User Interface Integration (UII) for Microsoft Dynamics CRM can be leveraged to deliver a composite Agent Desktop Application as shown below:


In this article I will be concentrating on the WPFCAB source code configuration, which is the next step of installing CCA.

After installing Customer Care Accelerator from


http://crmcca.codeplex.com/releases/view/44924 ,

it will create a Microsoft UII folder which will contain the below folders as shown:


According to the deployment guide named CCA Deployment Guide” present in the path : C:\Program Files (x86)\Microsoft Uii\CCA\Documentation\CCA Deployment Guide
,defines all the steps to modify configuration and build the UII solution.

The WPFCAB Source code can be downloaded from the below Url:

http://wpfcab.codeplex.com/releases/view/2005

The objective of modifying the solution is to build the solution successfully and get a modified Microsoft.Practices.CompositeUI.Windows.dll.

Last week for a project, I installed CCA R1 for CRM 4 and so also had to modify the solution by changing number of methods and removing some references to build the solution successfully.

Since I have the modified Microsoft.Practices.CompositeUI.Windows.dll ,so thought of sharing with you all to make the deployment of CCA R1 on CRM 4.0 easier.Download the file from the below link and rename it as Microsoft.Practices.CompositeUI.Windows.dll.
Microsoft.Practices.CompositeUI.Windows

Now you just need to paste the modified dll in the following path:


Hope this dll builds your solution successfully too and help to make the deployment easier for all of you.

Happy DeploymentJ!