NLog 自定义日志级别值
我有一个数据库,我正在尝试将消息写入其中,并希望使用 ${level} 布局,但我需要将其转换为 int 值以引用我自己的存储日志记录级别的表。是否可以将级别转换为配置中的枚举?还有其他想法吗?
I have a database I'm trying to write my messages to and would like to use the ${level} layout, but I need to translate it to the int value for reference to my own table that stores logging levels. Is it possible to maybe cast the level to my enum in config? Any other ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我还没有检查过这一点,但我怀疑你应该能够为 NLog 编写自己的布局渲染器(插件)来完成你想做的事情。 NLog 是非常可插入的:)
布局渲染器外观的快速示例(未测试...):
I have not checked this, but I suspect you should be able to just write your own layout renderer (plugin) for NLog to do what you want to do. NLog is very pluggable :)
A quick example of how a layout renderer could look (not tested...):
尝试这个解决方案:
Try this solution:
这是一个经过测试的布局渲染器,它将日志级别记录为整数。我获取日志级别的方式可能有点过分,但我正在经历 linq 阶段;-)
Here is a tested layout renderer that logs the log level as an integer. The way that I get the log levels is probably a little overboard, but I was going through a linq phase ;-)