Windows 表单应用程序中的日志记录错误
我有一个 Windows Forms NET 应用程序,它在不是我的开发机器的机器上出现间歇性行为。我需要在执行的各个阶段记录一些内部变量,以查看哪里出了问题。 (我也认为记录其他行为是个好主意,因此如果测试中遗漏了错误,可以了解该领域发生的情况)我发现了一些附加的东西可以做到这一点,但不仅如此看起来有点过头了,我想我想使用 NET 框架内置的东西来代替。据我所知,这意味着使用跟踪?使用跟踪(我可以找到)创建日志文件的所有示例均适用于控制台应用程序。有谁有创建日志文件并在执行期间将变量的状态写入/记录到日志文件的Windows窗体示例吗?我确实找到了一个记录到系统日志的示例,但即使对于测试版来说,这对我来说似乎也是一个坏主意。如果我从有困难的用户那里获得日志文件,我只想查看我的东西,而不是该机器上的所有东西,再加上从系统管理员的角度来看,我不希望应用程序在我的脑海中弄乱系统日志是操作系统的地方,而不是应用程序转储的地方。
I have an windows forms NET application that has intermittent behavior on a machine that is not my development machine. I need to log some of the internal vars at various stages of execution to see where things are going wrong. (also I think it is a good idea to log other behavior[s] so if there are bugs missed in testing can have some idea what is going on in the field) I found some add on stuff that does this but not only does it seem like over kill, I think I would want to use what is built in to the NET framework instead. From what I have read this means using trace?? All the examples to create log files using trace(that I can find) are for console applications. Does anyone have a windows forms example of creating a log file and writing/recording the state of vars during execution to the log file? I did find an example that logs to the system log but that seems like a bad idea to me even for a beta release. If I get a log file from a user having difficulty I only want to look at my stuff instead of every thing on that machine plus from a system admin point of view I wouldn't want an application cluttering up the system log in my mind that is for the operating system not a place for applications to take a dump.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
鉴于您已经说过您希望在框架中内置一些东西,这可能不是您想听到的,但我发现 log4net 工作得很好。如果它是您看过的“过度杀伤”框架之一,我不会感到惊讶。另一种选择,也是微软更认可的选择,是微软企业库——您可能会对日志框架感兴趣。 (信息此处,下载链接<一个href="http://www.microsoft.com/downloads/en/details.aspx?FamilyId=bcb166f7-dd16-448b-a152-9845760d9b4c&displaylang=en" rel="nofollow">此处。)
Given that you've already stated that you'd like something built into the framework, this probably isn't what you want to hear, but I have found log4net works very well. I wouldn't be surprised if it is one of the "overkill" frameworks you've looked at. Another option, and one that is more Microsoft sanctioned, is the Microsoft Enterprise Library -- you would be interested in the Logging framework. (Information here, download link here.)