In my API controller I'm define a string variable called log and I need to set value to that variable from the each calling methods.
for example, here is my controller method.
[HttpGet][Route("getData")] public async Task < IActionResult > GetPayementData() {
string log = DateTime.Now.ToString();
log = log + " This is Controller ";
var data = await _paymentRepo.DataTransfer(log);
return Ok(data);
}
here, I'm passing log variable value into a DataTransfer repository method and from there I'm again assign some value for it. This is how DataTransfer() method.
public async Task < sampleModel > DataTransfer(string log) {
log = log + DateTime.Now.ToString() + "This is Repository";
var sampleData = new sampleModel();
sampleData.ID = 1000;
sampleData.Name = "Stackoverflow";
return sampleData;
}
Finally, I need to get the log variable value from the controller, all after set value from the each methods to log variable. for example I need log final variable value as,
3/22/2022 9:55:07 PM This is Controller 3/22/2022 9:55:11 PM This is Repository
I tried to use ref
public async Task <sampleModel> DataTransfer(ref string log) {
}
But I can't use ref or out with the async methods. How can I resolve this. please be noted inside the repo method, which calling several sub methods and inside the each methods I need to set value to log variable.