Use case
I have the nlog.config for target: serverUrl="${var:serverUrl}"
This var is set at runtime, on the code when ASPCore startup, e.g NLog.LogManager.Configuration.Variables["serverUrl"] = xxx
The same to other dynamic value mechanisms.
Problem
Error in internalLog:
Exception: NLog.NLogConfigurationException: SplunkHttpEventCollector ServerUrl is not set!
We're checking the ServerUrl in InitializeTarget().
At this time, that var is not available yet, because it is set later at runtime.
Hence, exception is thrown and _hecSender is not initialized.
Proposal
Create _hecSender when needed, not at InitializeTarget.
Reference implementation: https://github.com/NLog/NLog/blob/dev/src/NLog/Targets/MailTarget.cs
Use case
I have the nlog.config for target:
serverUrl="${var:serverUrl}"This var is set at runtime, on the code when ASPCore startup, e.g
NLog.LogManager.Configuration.Variables["serverUrl"] = xxxThe same to other dynamic value mechanisms.
Problem
Error in internalLog:
Exception: NLog.NLogConfigurationException: SplunkHttpEventCollector ServerUrl is not set!We're checking the
ServerUrlinInitializeTarget().At this time, that var is not available yet, because it is set later at runtime.
Hence, exception is thrown and
_hecSenderis not initialized.Proposal
Create
_hecSenderwhen needed, not atInitializeTarget.Reference implementation: https://github.com/NLog/NLog/blob/dev/src/NLog/Targets/MailTarget.cs