问题
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