获取 log4net ADONetAppender 的条目 ID
我在 Web 应用程序中使用 log4net,并将所有页面错误记录到 SQL 服务器。我想知道是否有任何方法可以检索它生成的条目ID。我将离开这里找到的文档
http://logging.apache。 org/log4net/release/config-examples.html
我想使用此 ID 作为我可以向客户显示的参考号,以便他们可以联系客户支持在系统中查找,而不必通过日志档案。
I am using log4net in a web app, and log all page errors to a SQL server. I was wondering if there was any way to retrieve the entry ID generated by it. I'm going off of the documentation found here
http://logging.apache.org/log4net/release/config-examples.html
I want to use this ID as a reference number I can show to a customer so that they may contact customer support to lookup in the system and not have to go through a log file.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
除了按照 floyddotnet 建议编写自己的附加程序之外,您还可以考虑:
编写返回 ID 的附加程序会在您的应用程序和附加程序之间创建通常没有的依赖关系:Log4net 的设计将日志记录和在某处写入日志消息之间明确分开。您需要的附加程序会影响这种分离。
Apart from writing your own appender as floyddotnet suggested you could consider:
Writing an appender that returns the ID creates a dependency between your application and appenders that you normally do not have: Log4net was designed with a clear separation between logging and writing the log messages somewhere. The appender that you need would affect that separation.
由于 ID 是由数据库生成的,而不是由 log4net 生成的,因此我不认为您可以获得此信息。
在这种情况下,我使用 log4net 所做的就是在消息中包含一个精确到毫秒的日期时间戳,并将其作为参考号呈现给用户。然后您可以执行一个简单的 SQL 查询来获取日志表中的消息。
Since the ID is generated by the database and not by log4net, I don't believe this information is available to you.
What I've done in using log4net for such conditions is to include a datetime stamp in the message that goes down to the millisecond and present that to the user as a reference number. You can do then do a simple SQL query to get to the message in the log table.
我不确定它是否可行,但您可以为 log4net 编写自己的 Appender,最终将此信息存储在 log4net-context 中。
如何为 log4net 编写附加程序:
http://www.alteridem.net/2008/01/10/writing-an-appender-for-log4net/
上下文描述:
http://logging.apache.org/log4net/release/manual/contexts.html
I'm not sure its posible but you can write your own Appender for log4net end store this information in the log4net-context.
Howto writing an appender for log4net:
http://www.alteridem.net/2008/01/10/writing-an-appender-for-log4net/
Context-Description:
http://logging.apache.org/log4net/release/manual/contexts.html