views:

144

answers:

2

Disclaimer: I'm not a c++ developer, I can only do basic things. (I understand pointers, just my knowledge is so rusty, I haven't touch c/c++ for about 20 years :) )

The setup: I have an Outlook addin, written in C#/.Net 1.1. It uses a c++ shim to load.

Usually, this works pretty well, and I use in my c# code nlog for logging purposes. But sometimes, the addin fails to load, i.t. it does not hit the managed code at all for me to be able to investigate the problem from the log files.

So, I need to hook some basic logging into the c++ shim - just writing in a file. I need to make it as simple as possible for our users to enable. Actually I would prefer not to ship it by default.

I was thinking about something, which will check if a specific dll is present (the logging dll), and if so, to use it. Otherwise, it will just not log anything. That way, when I have a user with such a problems, I can send him only the logging dll, the user will save it in the runtime directory, and I'll have the file.

I guess this have to be done with some form a factory solution, which returns either a dummy logger, or if the dll is found, a real one.

Another option would be to make some simple logger, and rebuild the shim with or w/o using it, based on directives. This is not the desirable approach, because the shim needs to be signed, and I have to instruct the user to make a backup copy of the "real" one, then restore when done, etc., instead of just saving and deleting a dll.

I'd appreciate any good suggestion how to approach it, together with links or sample code how to go after this.

Cheers

+1  A: 

Why not have a registry key for that? The user opens regedit, adds a key and your library starts logging. The logging code will be in place all the time, just not invoked when the key is absent or set to "no logging".

sharptooth
yep, can be done. Just usually I do not like to ask users to touch their registry. Still, I'll need a sample code, or suggestion for some logging lib/framework.
Sunny
Yes but you can turn on the logging remotely if theres and issue and how is using a dll any easer for the users.
rerun
+2  A: 

The loading of the logging dll's seams like a complicated way of handling the configuration issue. Why not use the registry. If you use conditional loading on dlls you will be using LoadLibrary and GetProceAddress and as you said your not really a c++ coder so why introduce the complexity. Also there have to be n+1 c++ logging libraries available have you looked into any of those.


Some I found after a Google search

rerun
Yes, log4cplus is good too : http://log4cplus.sourceforge.net/
neuro