How to record Level:Error Logs to APM Errors

I have an application that will write logs to elasticsearch using serilog and is running APM on the docker-compose file. For some reason whenever I run the application and perform a task that will cause an error, it will not record on APM Error's tab, but it will record as an error on the Discover Error Logs which shows up as Level:Error.

enter image description here

On APM it does not show...

enter image description here

Is there a way I can convert that Level:Error log that is shown in the discover to an APM Error type of log so I can view it on the APM Error tab?

My controller that will handle the error (recording it to elasticsearch):

namespace CustomerSimulatorApp.Controllers
{
    public class SecondController : Controller
    {

        private readonly ILogger<SecondController> _logger;

        public SecondController(ILogger<SecondController> logger)
        {
            _logger = logger;
        }

        public IActionResult SecIndex()
        { 
            return View();
        }

        [HttpPost]
        public IActionResult SecIndex(TextInput form)
        {
            try
            {
               /* if (ModelState.IsValid)
                    return RedirectToAction("FinalIndex", "Final");
                else*/
                    throw new Exception("Looks like you did not type something!");
             
            }
            catch(Exception ex)
            {
                _logger.LogError(ex, "Empty textfield!");
                return RedirectToAction("FinalIndex", "Final");
            }
        }     
    }
}

APM errors are those errors that are captured by the APM agent, but errors captured by a logging integration are likely separate* (one integration captures them, described later).

There's a little bit of a conceptual overlap between the two, though it can be good to think of them as separate; APM errors are errors that should be recorded as part of a trace, whereas logging errors in the application may not be associated with an APM trace.

When APM agent is added to an application using the IHostBuilder extension method (ASP.NET Core and others), the APM agent registers a Microsoft.Extensions.Logging LoggerProvider with DI to capture logs at Error level or higher as APM errors. This capturing was added in 1.8.0.

For other logging frameworks, it'd be possible to write an integration to capture log events at the error level or higher using the .CaptureErrorLog(...) method on tracer, transaction and spans.

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.