log4net 和邮件

发布于 2024-08-05 22:29:37 字数 292 浏览 4 评论 0原文

我需要修改现有的程序,该程序通过写入访问文件来进行一些错误日志记录,它实际上使用 log4net dll(正如我们通过十六进制编辑器检查 dll 发现的那样),所以在想法上我需要使用以下命令重新编译调整后的 dll程序使用的原始版本。需求很简单,对于写入访问文件的一些错误,系统应该通过向管理员发送电子邮件自动警告他。

我应该查看项目和文档的哪些部分?作为一个刚接触 .net 平台以及 log4net 的人,我感到很迷茫。

编辑:似乎 log4net 的配置文件是嵌入的,因此无法直接访问配置。看来我需要另一种方法来解决这个问题。 问候

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

烧了回忆取暖 2024-08-12 22:29:37

您可能根本不需要更改 dll。您的 log4net 配置可能位于 App.config 文件中,或者位于 log4net.xml 等单独的配置文件中。

您可以严格使用配置文件为某些类型的错误设置电子邮件通知。

配置示例页面上有一个示例,只需搜索 SmtpAppender 即可。如果您需要控制将哪些消息发送到电子邮件,您可以查看 记录器和过滤器配置手册

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.

昇り龍 2024-08-12 22:29:37

如果您有程序的源代码,那么从硬编码配置更改为配置文件是相当简单的。

如果您无法访问源代码,我会使用
DateTime lastAccessTime = File.GetLastAccessTime(@"c:\file.txt");DateTime lastWriteTime = File.GetLastWriteTime(@"c:\file.txt"); > 使用第二个程序确定文件访问权限,并仍然使用 log4net 发送电子邮件。尝试调整 log4net.dll 要困难得多,并且从我的角度来看不建议这样做。

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.

浮萍、无处依 2024-08-12 22:29:37

你写的

好像是嵌入了log4net的配置文件
我想,你有几个选择:

如果您有原始程序的源代码,请不要嵌入 Log4Net 文件并根据 Don Kirkby 的建议进行更改(添加 SmtpAppender)。

如果您没有源代码但法律允许,您可以反汇编程序,更改嵌入资源(添加 SmtpAppender)并将其重新组合在一起(例如:csc.exe /out:main .exe /target:exe /resource:main.exe.config main.cs)。

或者,如果您没有源代码并且不允许进行逆向工程,您可以修改 log4net 的配置方式并加载另一个配置文件而不是嵌入的配置文件。为此,我想这个 XmlConfigurator类应该被修改。如果您的原始程序集是针对特定版本的 log4net 构建的,您可能需要添加 程序集重定向,以便使用您定制的 log4net.dll。
毕竟,您应该按照之前的建议配置 SmtpAppender。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文