-
Notifications
You must be signed in to change notification settings - Fork 151
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
How to use NLog in a .Net Core Console App #111
Comments
Yes it is! |
Thanks @304NotModified! Any examples on how to configure it? I was performing this: var loggerFactory = serviceProvider.GetService<ILoggerFactory>();
loggerFactory.AddNLog();
loggerFactory.ConfigureNLog("nlog.config"); but I was getting System.IO.FileNotFoundException: 'NLog.Web.AspNetCore'. I ended adding a nuget reference to NLog.Web.AspNetCore and now it is working. Doesn't seem right though; having a dependency on NLog.Web.AspNetCore in a console app. Maybe I was doing something wrong? |
NLog.Web.AspNetCore should not be needed. I will try to create an example |
@304NotModified can you clarify why there should be a dependency on NLog.Web.AspNetCore in a Console App? It's console app not a web app. Just curious. Thanks for your assistance here!! |
oops, ment NOT needed. Of course having a ASP.NET Core dependency in a console app would be ridiculous. Please note that earlier versions (the alphas) of NLog.Extensions.Logging where ASP.NET Core only as MS build it then only for ASP.NET Core |
I see, thanks @304NotModified. I figured out what I was doing wrong. From the nlog.config I got from my web project, it had: <extensions>
<!--enable NLog.Web for ASP.NET Core-->
<add assembly="NLog.Web.AspNetCore"/>
</extensions> Once I delete that, the exception went away. I created a sample app here to debug it. |
This example is for a full .net framework though, is there one for .net core 1.1? |
@304NotModified Both of these say we need to reference |
Why is this bug closed? |
there is no bug here. Maybe needs some docs, feel free to add to the wiki |
And example of the console is here: (using Autofac) bit hidden. We need to restructure the example folder I guess |
Thanks for the reply, unfortunately that is a .Net Framework 4.5.1 example. The title says he's looking for a .NET Core Console app example. I am too. I'll gladly add to the wiki if I can get something working, but so far no go. |
So the problem I was having is that it doesn't seem to automatically find the NLog.config file like it did in .Net Framework. Here's some sample code that works, with the caveat that I get a segmentation fault when the program exits. I'm using NLog 5.0.0-beta10. using System;
using NLog;
using NLog.Config;
namespace nlogging
{
internal class Program
{
private static void Main(string[] args)
{
LogManager.Configuration = new XmlLoggingConfiguration($"{AppContext.BaseDirectory}NLog.config");
var logger = LogManager.GetLogger("Example");
logger.Info("log info");
logger.Debug("log debug");
}
}
} |
That's indeed a known issue. Also in the .NET Core way you should use DI and .ConfigureNLog method |
There is a tutorial now (really for console!) |
If I'm building a .net core console app, is this the version of NLog I should use?
Thanks,
Mike D.
The text was updated successfully, but these errors were encountered: