ELMAH Implementation

I have an existing error exception handler

protected override async Task OnPageExceptionAsync(IDotvvmRequestContext context, Exception exception)
{
context.IsCommandExceptionHandled = true;

        if (exception is InvalidRouteException)
        {
            var baseException = exception as InvalidRouteException;
            context.RedirectToUrl("/Dashboard?ErrorMessage=InvalidUrl");
        }
        else if (exception is ForbiddenException)
        {
            var baseException = exception as ForbiddenException;
            context.RedirectToUrl("/Dashboard?ErrorMessage=Forbidden");
        }

        //or reroute back to previous url
        //var masterViewModel = context.ViewModel as MasterLayoutViewModel;
        //context.RedirectToUrl(masterViewModel.postbackurl);

        context.RedirectToRoute("Error", query: new { message = Constants.Error.ErrorMessage });
        await base.OnPageExceptionAsync(context, exception);
    }

now, how can I write the error details to ELMAH manually?

I have no idea how ELMAH works, but their documentation suggest you can configure it to process errors logger through the Microsoft.Extensions.Logging interface. You can obtain that logger from DotVVM request context by context.Services.GetRequiredService<ILogger<TheDeclaringExceptionHandler>>(), and then just call LogError with that exception.