在实时 Web 应用程序中注入日志记录的最快方法是什么?
我有一个实时 Web 应用程序,在一种特定情况下失败,但在本地运行良好。我没有远程调试设置,并且我想检查代码中某些变量的值。对我来说,记录/通过电子邮件发送/调试代码以查看这些值的最快方法是什么?
需要明确的是,没有抛出任何错误/异常。有些东西是不同的,它导致应用程序给出意想不到的结果。
提前致谢!
I have a live web application that is failing in one specific scenario, and locally it works fine. I don't have remote debugging setup, and I want to check the value of some of the variables in the code. What would be the fastest way for me to log/email/debug the code to view those values?
Just to be clear, there is no error/exception being thrown. Something is different, and its causing the application to give unexpected results.
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我会尝试使用 ASP.NET 跟踪 (https://web.archive.org/web/20210324184141/http://www.4guysfromrolla.com/webtech/081501-1.shtml)用于快速记录。您必须在代码中添加 Trace.Write() 调用,并且您可以在实时页面本身中看到日志(只需浏览)。
要获得更丰富的日志记录,您可以使用 log4net(只需谷歌“使用 log4net”,您将获得大量有用的链接),它易于配置,并允许您通过电子邮件发送日志(这非常方便!)。
希望有帮助。
I'd try with ASP.NET trace (https://web.archive.org/web/20210324184141/http://www.4guysfromrolla.com/webtech/081501-1.shtml) for quick logging. You will have to add Trace.Write() calls in your code and you can see the log in the live page itself (just by browsing).
For richer logging you can use log4net (just google "using log4net" and you'll get loads of useful links), which is easily configurable and allows you to send logs via email (which is amazingly handy!).
Hope that helps.
最快的方法是简单地在 Global.asax 文件中的 Application_Error 事件中实现一些日志记录。如果您没有 Global.asax 文件,只需使用 VS 新建文件向导创建一个文件,它就会为您处理该事件。
它不会帮助您获取错误范围内的局部变量,但您可以从那里记录全局变量,并至少获得有关错误内容的一些反馈。
编辑:为了回应您的评论,我建议您将跟踪数据输出到可以分析的文件中。我自己没有尝试过,但我看到有人推荐。在您的 web.config 中,添加名为 TraceListener 的内容,如下所示:
我确信您将需要在本地使用它。例如,确保跟踪对客户端不可见(这可能涉及使用 Trace 类打开或关闭跟踪,以及更改其写入的流)。
The fastest way is to simply implement some logging in the Application_Error event within your Global.asax file. If you do not have a Global.asax file, simply create one with the VS New File wizard and it'll handle that event for you.
It won't help you get to local variables at the scope of the error, but you can log global variables from there and at least get some feedback on what the error is.
EDIT: In response to your comment, I recommend you output your Trace data to a file that you can analyze. I haven't tried this myself, but I've seen it recommended. To your web.config, add something called a TraceListener like so:
You're going to need to play around with it locally, I'm sure. For instance, make sure the trace is not visible to the client (this may involve using the Trace class to turn the trace on or off, and changing the streams it writes to).
除了 JoshJordan 的评论之外,您还可以使用 Post Sharp 来跟踪何时输入方法而不是方法退出,看看有什么值进入其中......
In addition to JoshJordan's comment, you may be able to use Post Sharp to trace whenever a method is entered and not exited, and see what values are coming into it...
您始终可以打开仅本地调试,然后远程连接到服务器并使用该应用程序。
可能是查看您的问题的最快方法。
You can always turn on local only debugging and then remote on to the server and use the app.
Might be the fastest way to see your problem.