views:

212

answers:

3

I need to modify the existing program that does some error logging by writing to an access file and it actually uses log4net dll (as we found out by checking the dlls via hex editor) so in idea I will need to recompile the tweaked dll with the original that program uses. The need is pretty simple, for some errors that are written to the access file, the system should automaticly warn the admin via sending him an email.

What parts of the project and documentation shall I be looking at ? I am quite lost as a person who is very new to the .net platform aswell as log4net.

EDIT: It seems like the config file of log4net is embedded so no way to access the config directly. It seems like I will need another way to fix this. Regards

+5  A: 

You probably don't need to change the dlls at all. Your log4net configuration is probably in the App.config file, or a separate configuration file like log4net.xml.

You can set up e-mail notifications for certain types of errors strictly using the configuration file.

There's a sample on the configuration examples page, just search for SmtpAppender. If you need to control which messages get sent to e-mail, you can check out the sections of the configuration manual on Loggers and Filters.

Don Kirkby
+1  A: 

If you have the source code of the program, then it is rather simple to change from a hard-coded configuration to configuration file.

In case you have no access to the source code, I would use DateTime lastAccessTime = File.GetLastAccessTime(@"c:\file.txt"); or DateTime lastWriteTime = File.GetLastWriteTime(@"c:\file.txt"); to determine the file access with a second program and still use log4net to send the emails. Trying to tweak the log4net.dll is a lot harder and not recommended from my pov.

weismat
+1  A: 

You wrote

It seems like the config file of log4net is embedded I guess, you have a few options:

If you have the source code of the original program, do not embed the Log4Net file and change it according to Don Kirkby suggestions (add a SmtpAppender).

If you don't have the source code but you are legally alowed to, you can disassemble the program, change the embedded resource (add a SmtpAppender) and put it back into together (e.g.: csc.exe /out:main.exe /target:exe /resource:main.exe.config main.cs).

Or, if you don't have the source code and are not allowed to reverse engineer, you can modifiy the way log4net gets configured and load another configuration file instead of the embedded one. To do this, I guess this XmlConfigurator Class should be modified. If your original Assembly has been build agains a specific version of log4net you might want to add an assembly redirect so your costumized log4net.dll is used instead. After all you you should configure a SmtpAppender as suggested earlier.

tobsen