Introducing CRM 2011 Appender for log4net

Posted by on May 6, 2012  |  commentsComments (4)

I am pleased to announce the new CRM 2011 Appender for log4net!  This will allow developers to easily log messages from a custom process to a custom Log entity within your CRM 2011 organization.  The advantage of this over the basic log4net file appender is that Administrators can view these messages from within the CRM UI instead of finding a file that is stored somewhere on the CRM server.

The CRM 2011 Appender is built on the log4net library so it comes with all the features of log4net such as filtering messages to log by level (debug, info, warning, error, fatal) and a variety of tokens to use in the message output.

The project on CodePlex comes with a sample Log entity that can be used to store log messages.  It has a custom message attribute to store the actual message and a custom Level attribute to store the level of the message (debug, info, warning, error, fatal). 


Note:  To limit the amount of records created in a production environment, it is recommended to set the log4net Threshold to only log Warnings and Errors.

For more information about the CRM 2011 Appender and how to use it, check out the documentation on CodePlex -

Follow the project for future updates and feedback or feature requests are greatly appreciated!


  1. Hi Blake, the article and the project is really great, but the documentation in codeplex is really few.

    How can I use it in plugins, does I have to use ILMerge to upload the log4net library + the Appender + the Plugin?
    Do I have to create the table where is logged the information? or the appender creates it the first time used?

    Posted by: Marco Medrano  |  Apr 9, 2013 6:45:37 PM

  2. Marco,

    There is a note in the documentation that this is currently not recommended for plugins. In a plugin, it requires the org service to be instantiated each time in order to have the correct context, but this causes issues with log4net because it will create duplicate log messages so it doesn't play well in plugins.

    You have to create the Entity in CRM for the logging information. Then you setup your appender to point to your entity. The downloads page provides a sample Entity customization that you can use as well.

    Hope this helps.

    Posted by: Blake Scarlavai  |  Apr 10, 2013 9:23:06 AM

  3. Thanks Blake, Would be great have this working for plugins.
    I think is not needed a new instance of "org service", it already come in the parameters of a plugin and works fine to use LinQ and early binding.
    We should be able to use something like:

    protected void ExecutePreQuoteProductCreate(LocalPluginContext localContext)
    Crm2011Appender appender = new Crm2011Appender();
    appender.OrganizationService = localContext.OrganizationService;

    A plus of this, is that is not needed request the credentials (that would be a headache on plugins).
    What do you think?
    I dont know if the issue of "duplicate log messages" would persist in this case.

    Posted by: Marco Medrano  |  Apr 11, 2013 11:13:39 AM

  4. I tested what I wrote you, and it worked :).

    Posted by: Marco Medrano  |  Apr 12, 2013 12:17:08 PM

Post a Comment

  • *Required

Contact Us for a Quote, or Personalized Demonstrationof Microsoft Dynamics CRM for Your Business.

Contact Us