question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Should Factory.CreateInstance ignore NLog.Web errors?

See original GitHub issue

In 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:closed
  • Created 4 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ThomasArdalcommented, Sep 23, 2019

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 to true, NLog should indeed complain.

1reaction
snakefootcommented, Sep 22, 2019

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found