Using elmahr.elmah in winform application

左心房为你撑大大i 提交于 2019-12-12 00:38:22

问题


I have recently shown to my team leader the ElmahR Dashboard and now he wants to implement ExceptionsLog with ElmahR in all of our current projects, including those that are Winform Applications, and after many days of searching I can't find a way to add a Winform Application as "ElmahR source".

Does anyone have a clue?


回答1:


ErrorPostModule in ElmahR.Elmah does not support Winforms apps because it's been written to be an ELMAH module, so it's tied to an ASP.NET lifecycle and cannot be easily adapted. That said, ErrorPostModule does not do anything so magic and can be easily taken as a guideline to write a small "handler" to be used in a Winforms app. Take a look at its code here, what you should do is:

  • replace what's in the OnInit method, which simply reads configuration bits and attaches the error handler
  • when an error occurs, handle it like it's done in the SetError method to post it to the right destination reading the configuration parameters you read before. You would reference ELMAH and create an Error instance from your exception, and then use ErrorJson.EncodeString to encode it

You may want to borrow the W3.cs file to simplify the http form compilation.

At some point I might generalize this work and put it in ElmahR.Elmah, but not sure when I'll be able to do it.




回答2:


I just forked the elmahr source code to work on this, I want to post errors from console applications, so I'm going to remove the dependency on Elmah and create the "error" objects and send them to the dashboard.

It's a work in progress but can be used as starting point for solving your problem.

https://bitbucket.org/rudygt/elmahr

Update: the fork now include full support to post to ElmahR using a ServiceStack endpoint, using json over http. This remove the dependency over the original Elmah to publish errors to the dashboard. The first example is a C# Console Application



来源:https://stackoverflow.com/questions/16110964/using-elmahr-elmah-in-winform-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!