views:

203

answers:

1

I'm working on converting a crm 3.0 callout library, and would like to use log4net for logging. I am able to get the library to compile and deployed to my crm server, but I can't seem to get it to log. I'm using a RollingLogFileAppender. I put the log4net.config and compiled versions of the library in the \server\assembly folder. I have trace logs enabled in crm and no errors are logged here or in event viewer. I've granted full access rights to the network service user on the \server\assembly folder and this is also where I've configured the log4net logs to be written to.

When I write my own log method using StreamWriter, it does work, but I would rather use log4net.

I have a feeling that log4net cannot find the log4net.config, but I'm not sure how to determine this without going through the trouble of remote debugging or adding additional debug code to the log4net library.

Any suggestions?

+1  A: 

For plugins/workflow activities, your configuration file will be relative to the \Microsoft Dynamics CRM\Server\bin directory (assuming you're using a relative path). I use a single assembly for both the CRMWeb\bin and \Server\bin directories so I actually have two configuration files. One is at CRMWeb\ISV\MyISV\log4net.xml and the one for plugins/workflows is located at \Microsoft Dynamics CRM\Server\bin\ISV\MyISV\log4net.xml.

In my assemblyinfo.cs I have the following specification:

[assembly: log4net.Config.XmlConfigurator(ConfigFile = "ISV\MyISV\log4net.xml", Watch = true)]

Once you're sure that you're looking in the right place for your configuration file... If you're still having trouble with normal rolling files, set up an smtp appender to see if you get e-mails. I've found the I have very limited permissions running as plugins/workflows and don't have access to the file system. You'll want to make sure you can write to the specified directory (which it sounds like you can).

Let me know if this helps.

EDIT: My experience is with CRM 4.0, so I would adjust the paths as necessary.

benjynito
Re-reading, it seems the only difference is mine are in the \Server\bin where as yours are just in \Server. Did 3.0 have the \Server\bin directory?
benjynito
I do not have a AssemblyInfo.cs in any of my CRM 4.0 folders. Is there somewhere else I should define the location of the configuration file?
KClough
The assemblyinfo.cs file will be a part of your c# project, under Properties. My guess is with nothing specified, it will be looking in Server\bin directory. Does 3.0 just have \Server\assembly with no bin folder between? You might just try the \Server directory to place your configuration. You might also try to explicitly call one of the log4net.Config.XmlConfigurator.Configure overloads as you find most convenient within your plugin. If the parameterless doesn't help, try specifying the FileInfo parameter.
benjynito
I ended up calling the configure method. Thanks so much for your help. I have one other crm question on StackOverflow that is still outstanding if you want to take a crack at it. http://stackoverflow.com/questions/2000877/crm-3-0-callouts-running-in-crm-4-0-causing-infinite-loop
KClough