-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cant get Seq target to work with $configsetting #46
Comments
NLog is having a hard time with dependency injection and lazy initialization. Trying to improve on this in NLog 5.0 but until then you have to help out yourself. Manual load configuration before loading NLog.config: var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddEnvironmentVariables();
Configuration = builder.Build();
NLog.Extensions.Logging.ConfigSettingLayoutRenderer.DefaultConfiguration = Configuration;
// Now we are ready to load the NLog-config
var logger = NLog.Web.NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger(); Another solution is to remove all code related to NLog. So remove call to NLogBuilder and remove any creation of NLog Logger-objects until having called See also: NLog/NLog.Extensions.Logging#265 |
Guess some magic could be sprinkled into this class, so delay the rendering of URL until start writing LogEvents. This would have the side-effect that wrong configured SeqTarget would only be discovered when starting logging, instead of at startup. |
Thanks for your advice, @snakefoot. I think, if possible, we should stick to standard NLog initialization (avoid sprinkling magic) in order to keep the sink better aligned with the rest of the NLog ecosystem, especially given the workarounds you mentioned. @SirGordon please let us know if you're still blocked after trying the options above. Thanks for dropping by! |
Thank you very much for quick responses, both ways work fine. |
NLog.Web.AspNetCore ver 4.9.3 has been released, and now you can do this:
That replaces the old style:
|
[Four years pass] I have code that uses the "new" style
and this worked fine with NLog 5.3.4 under net8.0. But changing the project target to net9.0 causes this same line (with same appsettings.json and NLog.config) to throw Suggestions? |
@RWells-HUHS Please create new issue for your special problem, instead of awaking old issues. NLog and Seq should ofcourse work with NET9, so for your new issue please include your |
@snakefoot : Sorry for waking up old daemons. This page was the only hit on this exception and this NLog initialization call... However, I also realize now this is the home for discussions of Seq, which I'm not using. So, apologies for that, too. Nonetheless, I appreciate your suggestion of consulting the Internal Logger. I already have it configured, but the log level is Info, so I'll make that more verbose and hopefully that will help me troubleshoot further. |
Hello,
This example https://github.com/304NotModified/NLog-Demo-cases/tree/master/AspNetCore2WithConfigSetting
works fine unitl I try to add a Seq target with a
${configsetting}
To reproduce:
Target.Register<SeqTarget>("Seq");
as first line in Program.cs"serverUrl": "http://webtest4:5341/"
to appsettings.json<PackageReference Include="NLog.Targets.Seq" Version="1.2.0-dev-00075" />
to csprojinternal log:
Am I doing something wrong?
The text was updated successfully, but these errors were encountered: