Below I am writing to a Serilog logger text file a user name variable, transaction name variable and a dictionary with 10 elements. This work perfectly as you can see from the logger output below.
var array1 ={"User name:", "Transaction:" ,"Transaction values:"};
var array2 = new object[] { MyUser.userId, MyTransSeq.transactionId, MyVarValueDict };
for(int j=0; j< array1.Length; j++)
{
text = text + list1[j] + " {"+j+"} ";
}
MyGlobals.logger.Information(text, array2.ToArray());
Output from above code
2015-01-29 21:20:57.935 +00:00 [Information] User name: "pclarkeirl" Transaction: "initmenu01" Transaction values: [("<&option>": " "), ("<&envname>": "\" \""), ("<&test>": "MYTESTVALU"), ("<&envcount>": "3"), ("<&companyid>": "strykerlmk"), ("<&envdesc1>": " "), ("<&envdesc2>": " "), ("<&envcolour>": " "), ("<&count>": " "), ("<&selopt>": " ")]
I now want to change this so that rather than hard code the variables, the user can select which variables are to be logged. So the user can type in the list of fields as a comma delimited field such as “MyUser.userId, MyTransSeq.transactionId, MyVarValueDict” and this is written to array2. The contents of array2 now contain:
[0]=“MyUser.userId”,
[1]=”MyTransSeq.transactionId”,
[2]=“MyVarValueDict”
The problem is that they are now Text values in quotes. So my question is How can I turn a text array value such as “MyUser.userId” back into an object. Below is some code I have tried without success ?
string[] userSelArray={"MyUser.userId", "MyTransSeq.thisTransId", "MyVarValuesDict" };
string[] array1 = { "User name:", "Transaction:", "Transaction values:" };
object[] array2 = new object[array1.Count()];
string text = "";
for (int j = 0; j < array1.Length; j++)
{
text = text + array1[j] + " {" + j + "} ";
array2[j] = userSelArray[j];
}
MyGlobals.logger.Information("NEXT" + text, array2.ToArray());
Output from above code
2015-01-29 22:01:44.502 +00:00 [Information] NEXTUser name: "MyUser.userId" Transaction: "MyTransSeq.thisTransId" Transaction values: "MyVarValuesDict"
Above you can see that the variable names treated as text and are not being translated