在 C# 中将整个对象转储到日志的最佳方法是什么? [英] What is the best way to dump entire objects to a log in C#?

查看:17
本文介绍了在 C# 中将整个对象转储到日志的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,为了在运行时查看当前对象的状态,我非常喜欢 Visual Studio 即时窗口提供的内容.做一个简单的

So for viewing a current object's state at runtime, I really like what the Visual Studio Immediate window gives me. Just doing a simple

? objectname

会给我一个格式很好的对象转储".

Will give me a nicely formatted 'dump' of the object.

是否有一种简单的方法可以在代码中执行此操作,以便我可以在记录时执行类似的操作?

推荐答案

您可以基于 Linq 示例.
也看看这个相关问题的答案以获得一个样品.

You could base something on the ObjectDumper code that ships with the Linq samples.
Have also a look at the answer of this related question to get a sample.

这篇关于在 C# 中将整个对象转储到日志的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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