使用NLog从数据库返回ID? [英] Returning a id from database with NLog?

查看:85
本文介绍了使用NLog从数据库返回ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在将异常记录到SQL Server数据库中的表的同时,id每行都会增加.使用NLog登录时,我需要将此ID返回给用户,这可能吗?如果可以,怎么办?

While logging exceptions to a table in the SQL Server database the id will increase with each row. I need to return this id to the user while logging with NLog, is this possible? And if so, how?

注意:我只有NLog Logger类的一个实例,并且确实有一个自定义目标(TargetWithLayout),用于处理数据库通信.

Note : I got only one instance of the NLog Logger class and I do have a custom target (TargetWithLayout) that handle the database communication.

推荐答案

此问题通过执行一个自定义目标来解决,该目标将记录到数据库,然后在通过NLog发送给目标的参数上设置ID.然后可以使用该对象从调用方法获取日志ID(对象是ref).

This was solved by doing a custom target that logges to database and then sets the ID on the parameter sent to the target through NLog. This object can then be used to get the log id from the calling method(object is a ref).

这篇关于使用NLog从数据库返回ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆