This project is read-only.


There are two ways to setup the CRM 2011 Appender. You can set it up programmatically or using the application config.



Create a new instance of the Crm2011Appender:
Crm2011Appender appender = new Crm2011Appender();

Set the threshold of log messages that will actually be created:
appender.Threshold = Level.Debug;

Note:  In production environments, it is recommended to set the threshold to Warn in order to limit the amount of records being created.

Set the layout for your log messages:
appender.Layout = new log4net.Layout.PatternLayout("%5level - %message%newline");

Setup your Organization Service and set the property on the appender:
var creds = new ClientCredentials();
var orgService = new OrganizationServiceProxy(new Uri("http://server/org/XRMServices/2011/Organization.svc"), null, creds, null);

appender.OrganizationService = orgService;

Set the schema name for the Log entity in CRM:
appender.LogEntity = "new_log";

Set the schema name for the Message attribute that contains the log message:
appender.MessageAttribute = "new_message";

Set the schema name for the Level attribute that contains the level of the log message (this is optional):
appender.LevelAttribute = "new_level";

Configure log4net:


Application Config

The following app.config is a sample of how to set up your config for the CRM 2011 Appender.  It requires the organization service url and creds (if necessary).  The LogEntity and MessageAttribute are the schema names for your Log entity in CRM and the attribute of that entity that stores the log message.  The LevelAttribute is optional and should be the attribute on the Log entity where the level of the log will be stored (Debug, Info, Warn, Error, Fatal).

Note:  In production environments, it is recommended to set the threshold to Warn in order to limit the amount of records being created.

<?xml version="1.0"?>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net, Version=, Culture=neutral, PublicKeyToken=1b44e1d426115821"/>
    <appender name="CRM" type="SonomaPartners.Crm2011Appender.Crm2011Appender, SonomaPartners.Crm2011Appender">
      <OrganizationServiceURL value="http://server/org/XRMServices/2011/Organization.svc" />
      <UserName value="username" />   <!-- optional -->
      <Domain value="domain" />       <!-- optional -->
      <Password value="password" />   <!-- optional -->
      <LogEntity value="new_log" />  
      <MessageAttribute value="new_message" />
      <LevelAttribute value="new_level" />   <!-- optional -->
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date %-5level - %message%newline"/>
      <filter type="log4net.Filter.LevelRangeFilter">
        <levelMin value="DEBUG"/>
        <levelMax value="FATAL"/>
      <appender-ref ref="CRM"/>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>

Check out the log4net site for more information on configuring log4net -

Last edited Jan 21, 2014 at 2:50 PM by bscarlavai, version 6


mezhavecis Nov 7, 2012 at 10:09 AM 
Can you please write, where must be located log4net XML configuration for CRM plugin or workflow.