Should Factory.CreateInstance ignore NLog.Web errors?
See original GitHub issueIn my target I have a layout looking like this:
public Layout HostnameLayout { get; set; } = "${event-properties:hostname:whenEmpty=${aspnet-request-host:whenEmpty=${machinename}}}";
Basically, I want to try and render a hostname by looking at various properties. If the user specify a structured variable named hostname
, I will use that. If not, I look for an aspnet-request-host
. If not there I try to pull the machinename
.
The main challenge here is that the CreateInstance
method of the Factory
class, throws an exception if someone adds my target to their code but not add the NLog.Web
package. I want to allow people running without the NLog.Web
package, but I don’t want the config causing an exception.
Is there some way to avoid this or should it maybe be allowed to reference layout renderers that may or may not be there?
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
NLog Exception when parsing nlog.config - Target cannot ...
I tried writing NLog. config nad nlog. config for the filename and at this code line above.
Read more >Configuring NLog in ASP.NET Core web app | by Jovan Popovic
First we need to start with adding the NuGet packages. You can install NLog, NLog.Web.AspNetCore and other necessary NuGet packages for the targets...
Read more >NLog 5.0 - List of major changes
NLog tries to handle this by making ResolveService() throw exception when wanted dependency is not yet available. When InitializeTarget() fails ...
Read more >LayoutRenderer cannot be found: 'aspnet-user-identity'
Now, I've verified that I am including a reference to NLog and NLog.Extended. Both DLLs exist in the bin folder of my web...
Read more >NLog error when opening Tentacle Manager - Uncategorised
I have confirmed that this problem is resolved by removing the aspnet-user-identity param from the machine.config. Other than move the NLog ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Didn’t know about
throwConfigExceptions=false
. I had it in the sample code. Must have been a copy-paste from somewhere. It now makes total sense to me and I agree. If users set this totrue
, NLog should indeed complain.If you want a soft dependency on NLog.Web and NLog.Web.AspNetCore. Then I guess you need to assign the layout on InitializeTarget instead of in constructor, and have some fallback mechanism if the wanted layoutrenderer is not yet available. See also my ramble here: #3557