Returning a id from database with NLog?

若如初见. 提交于 2019-12-12 03:44:40

问题


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?

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


回答1:


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).



来源:https://stackoverflow.com/questions/37589065/returning-a-id-from-database-with-nlog

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!