Log something into radzen.._log

How can I log own debug messages in the razen log?


Deployed Radzen applications use the default ASP.NET logging. There isn't anything Radzen related.

But how do you inject the logger into the Radzen pages (e.g. "Pages\MyPage.razor") so it can be used from event handlers, for example? First I tried using constructor DI in the customizable MyPage.razor.cs:

private readonly ILogger<MyPageComponent> _logger;
public MyPageComponent(ILogger<MyPageComponent> logger)
     _logger = logger;

and then using _logger.LogDebug etc in the event handlers. But this produces build error "There is no argument given that corresponds to the required formal parameter 'logger' of 'MyPageComponent.MyPageComponent(ILogger)'

This approach worked (in MyPage.razor.cs):

protected ILogger<MyPageComponent> _logger { get; set; }

However it requires the use somewhere of
global using Microsoft.Extensions.Logging;
otherwise the Radzen-generated code in MyPage.razor.designer.cs cannot use the extension methods _logger.LogDebug etc.
I put it in Program.cs which is excluded from Radzen modifications in my project. There may be a better place e.g. a special module GlobalUsings.cs.

This is how you should do it.

This is one way of doing it otherwise you should use a custom method in your *.razor.cs file (which Radzen will not overwrite).