Dump an object in tests and sandbox apps
- reference the nuget ObjectPrinter package
- use the static class ObjectPrinter.Config to set default behavior for your application
- print to console: Console.Out.WriteLine(someObj.Dump())
- print to output stream: someObj.DumpTo(Console.Out)
Dump an object using log4net
- add to the first line of the log4net config section
<renderer renderingClass="ObjectPrinter.Log4Net.Log4NetObjectRenderer, ObjectPrinter.Log4Net.v1212" renderedClass="System.Object" />
- register Log4NetTypeInspector
Config.Inspectors.Registration = new TypeInspectorRegistration().RegisterInspector(new Log4NetTypeInspector()).GetRegisteredInspectors();
- Log.Error(ex);
Capturing more context in an exception
try
{
...
}
catch(Exception ex)
{
ex.SetContex("userId",userId);
throw;
//or
Log.Error(ex);
}