开发者

c++ simple conditional logging

开发者 https://www.devze.com 2022-12-23 02:58 出处:网络
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 :) )

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


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

  • log4cpp
  • rlog


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".

0

精彩评论

暂无评论...
验证码 换一张
取 消