I am working on logging exceptions. Now I have an ability to throw exceptions with any parameters and give them to log method. I want to display Name, Type and Value of each parameter in log-message. There are no problems with Type and Value, but I cannot get the Name of variable. I don't want to double the amount of parameters, adding nameof(Value) for each parameter when throwing.
This is how I throw with different parameters:
throw new TestException(new object[]{ var0,
var1,
var2,
var3,
var4 });
This is how I don't want to throw them:
throw new TestException(new object[]{ var0, nameof(var0)
var1, nameof(var1)
var2, nameof(var2)
var3, nameof(var3)
var4, nameof(var4) });
These are my thoughts about wrapping data in object:
public class ArgWrapper
{
public ArgWrapper()
{
}
public string Type { get; set; }
public string Name { get; set; }
public object Value { get; set; }
}
As result, I want to have collection of objects with such fields, so then I would log the info about each parameter like: { Type: "type", Name: "name", Value: "value" }