locked
Log4net to log in separate SQL db with mscrm 2011 plugin RRS feed

  • Question

  • Hi,

    I need to use log4net to log into separate sql db in custom table with plugin in mscrm 2011 on premise, I am able to log into file(notepad) but this does not work when i change log4net config for writing into SQL db but Same config file works in other console application.

    Thanks in anticipation

    Pinku Kumar

    Thursday, January 21, 2016 8:43 AM

All replies

  • Hi,

    I need to use log4net to log into separate sql db in custom table with plugin in mscrm 2011 on premise, I am able to log into file(notepad) but this does not work when i change log4net config for writing into SQL db but Same config file works in other console application.

    Thanks in anticipation

    Pinku Kumar

    One thing you may want to consider with Log4Net:  I believe the default, and possibly only behavior, is to write calls using non-blocking logic.  If Log4Net is leveraging background threads you may run into problems with threads staying alive longer than your plugin execution time.  As a general rule, I recommend avoiding logging in this manner inside of CRM plugins because of concerns with performance and blocking/non-blocking issues like I previously mentioned.  It tends to get overused or used incorrectly and can lead to unintended behavior. 

    The direct answer to your question is:  There are many restrictions around what CRM allows you to do inside plugin logic.  I'm not familiar with the mechanism Log4Net uses for its SQL Adapter, but I believe SQL database calls are forbidden in CRM plugins running in Isolation mode.  If you're on premise you could register the plugin in full trust and try again. 

    The alternative I suggest would be to deploy a WCF or ASPX web service on top of the logging database.  Sandbox plugins have access to web services without elevated privileges so you should be able to achieve the same result with one extra hop. 

    • Marked as answer by Pinku Kumar Friday, January 22, 2016 1:32 AM
    • Unmarked as answer by Pinku Kumar Friday, January 22, 2016 1:32 AM
    Thursday, January 21, 2016 4:41 PM