I'm using Nlog with Application Insights as Target in a WebJobs project to log telemetry. Everything seems to be working if I log just the message like below.
_logger.Log(LogLevel.Info, "Job completed");
I can see the Trace Info in application insights with the message "Job completed"
But I wanted to log some parameters along with the message like below.
_logger.Info($"Job created successfully", req.UserId, req.ReportName, jobId, searchString);
or like below
catch (Exception ex)
{
_logger.Error(ex, "Error creating the job", req.UserId, req.ReportName, searchString);
throw;
}
I'm expecting a trace in application insights containing the parameters which I passed along with the message. But I can only see the message but not any parameters or exceptions details.
What am I missing?
Edit:
NLog nuget version 4.3.8 and Microsoft.ApplicationInsights.NLogTarget nuget version 2.4.1
More Code:
try
{
var jobId = _reportingService.RequestReport(req.ReportName, searchString).Result;
_logger.Info($"Job created successfully", req.UserId, req.ReportName, jobId, searchString);
var output = new RetrieveReportDataRequest()
{
CreationRequest = new ReportCreationRequest()
{
ImmutableUserId = req.UserId,
...
},
SearchParameters = searchString,
JobId = jobId,
Created = DateTime.UtcNow,
};
outputQueueMessage = JsonConvert.SerializeObject(output, settings);
}
catch (Exception ex)
{
log.WriteLine(ex.Message);
_logger.Error(ex, "Error creating the job", req.UserId, req.ReportName, searchString);
throw;
}