良好的示例.Net Windows 服务报告错误
我正在编写一个 Windows 服务,它将进行大量的网络通信(在共享文件夹中复制许多文件并修改数据库)。
我需要一种方法来通知用户(如果已登录)任何异常/错误。我的问题是对错误进行分组以将其(通过电子邮件)发送到管理员地址。
我知道事件记录既没有从系统托盘中弹出通知,但管理员不会查看该日志,他更喜欢电子邮件。
理想的组件是 ASP.NET 运行状况监控,但仅适用于 IIS,并且需要与 Windows 服务类似的组件。
关于此问题的任何 C# 或其他语言(带有源代码)中的示例应用程序 Windows 服务?
I am writing a windows service that will be doing a lot of network communication (copy many many files in shared folders and modify database).
I need a way to notify a user (if logged on) of any exceptions/errors. My issue is do group to errors for send it (by email) to administrator address.
I am aware of event logging neither notification bubble from system tray, but the administrator not views that log, he prefers email.
The ideal component is ASP.NET Health Monitoring, but only works for IIS, and it is required a component similar for Windows Services.
Any sample application Windows Service in C# or another language in .net (with source code) about this issue ??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您只需要一种发送电子邮件通知的方法,.Net 具有 SMTP 和邮件类型来处理此问题。电子邮件通知在软件中不再常见,这就是常用功能已合并到基类库中的原因。
您可以使用 SmtpClient、MailAddress 和 MailMessage 对象来完成发送电子邮件通知所需的任务。当然,您需要访问 SMTP 服务器才能传输邮件,因此请找出其主机地址以正确配置您的应用程序。下面是一些示例:
该示例只是直接代码,但最好将其放入可重用的方法中,如下所示:
If you're just needing a way to send an email notification, .Net has SMTP and mail types to take care of this. Email notifications are common in software anymore and that's why the commonly used functionality has been incorporated into the base class lib.
You could use SmtpClient, MailAddress, and MailMessage objects to accomplish what you need to simply send an email notification. Of course you need to have access to an SMTP server to transmit the mail, so find out what its host address is to properly configure your application. Here are a few examples:
That example is just straight code, but it would be better to put it into a reusable method like this:
检查这个:http://www. codeproject.com/Articles/16335/Simple-Windows-Service-which-sends-auto-Email-aler
如果这是第一次使用 Windows 服务(因为 Windows 服务很难调试),我的建议
check this : http://www.codeproject.com/Articles/16335/Simple-Windows-Service-which-sends-auto-Email-aler
my advice if it's first time to work with windows service (because Windows Service is very hard to debug)