Skip to content
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

Move the extension method that need Microsoft.AspNet.Hosting into ex NLog.Extensions.Logging.Hosting #25

Closed
Tasteful opened this issue Mar 14, 2016 · 13 comments · Fixed by #82

Comments

@Tasteful
Copy link

Move the extension method that need of Microsoft.AspNet.Hosting dependency to own assembly to not get all the extra dependencies into the library when using the package from ex class library.

I'm using Microsoft.Extensions-package but running them from asp.net webforms application without dnx support.

@Tasteful Tasteful changed the title Move the extension method that need of Microsoft.AspNet.Hosting into ex NLog.Extensions.Logging.Hosting Move the extension method that need Microsoft.AspNet.Hosting into ex NLog.Extensions.Logging.Hosting Mar 14, 2016
@304NotModified
Copy link
Member

That's a good idea, but we need then an additional (NuGet) package?

The code that uses Microsoft.AspNet.Hosting is AspNetExtensions.cs.

@304NotModified
Copy link
Member

Maybe we have to move all the aspnet5 stuff to https://www.nuget.org/packages/NLog.Web.ASPNET5

It has already a dependency to Microsoft.aspnet.hosting.

@apawsey
Copy link

apawsey commented Apr 13, 2016

Remember that .net core is not just for ASP.NET, therefore we preferably need NLog support without dependencies on the ASP.NET parts. Microsoft's naming convention appears (looking at the rc2 and rc3 packages that have started appearing) to be adding .dnx onto a package when it goes beyond the standard core areas... although all the naming is still completely confusing at this point.

@304NotModified
Copy link
Member

I agree this needs to be fixed, but I isn't clear to me what the best solution is. Without that I can't start of course :)

Do you have examples of new packages regarding with dnx/rc3?

@304NotModified
Copy link
Member

Also confusing, the repository of Microsoft.extensions.Logging is called aspnet/Logging ;)

https://github.com/aspnet/Logging

@304NotModified 304NotModified modified the milestone: 2.0 Apr 15, 2016
@304NotModified
Copy link
Member

Will do this in the near future

@304NotModified
Copy link
Member

@Tasteful

Any idea how this should work in a .NET Core Console application? How do we get ILoggerFactory?

NB: the DI feature is removed in non-asp.Net: http://www.inversionofcontrol.co.uk/asp-net-core-1-0-dependency-injection-what-is-is-and-what-it-is-not-2/, the main method needs to be static again.

@304NotModified
Copy link
Member

304NotModified commented May 27, 2016

Got the solution for the console app:

example

See aspnet/Logging#439

@Tasteful
Copy link
Author

@304NotModified Sorry for late reply. I have another approach to start a console application to also use the dependency injection as in the asp.net core application.

The program with the static main is only containing the application starting/configuration options and that is creating; from dependency injection, and calling the main-method.

using System;
using System.IO;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

namespace DataFeeder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var services = new ServiceCollection();

            var config = new ConfigurationBuilder()
                .SetBasePath(Environment.CurrentDirectory)
                .AddJsonFile("default.json")
                .AddJsonFile($"test.{Environment.MachineName}.json")
                .AddEnvironmentVariables()
                .Build();

            // Configure the options
            //services.Configure<ImportOptions>(config.GetSection("import"));

            // Add program itself
            services.AddTransient<Runner>();

            var serviceProvider = services.BuildServiceProvider();
            serviceProvider.GetRequiredService<ILoggerFactory>().AddConsole((title, level) => title.Contains("DataFeeder") && level > LogLevel.Debug);

            // Start program
            serviceProvider.GetRequiredService<Runner>().Main(args);
        }
    }

    public class Runner
    {
        private readonly IServiceProvider _serviceProvider;

        public Runner(IServiceProvider serviceProvider)
        {
            _serviceProvider = serviceProvider;
        }

        public void Main(string[] args)
        {
            // do stuff...

        }
    }
}

@qrli
Copy link

qrli commented Jan 11, 2017

I'm also trying to use this in non-asp.net-core console application but scared off by the asp.net core host dependencies. I'm currently using Serilog as an alternative solution, but I'd like to go back to NLog when this issue is solved.

@304NotModified
Copy link
Member

We have to do the following to remove the dependency to ASP.NET for this package

  1. document the new layout renderers (which are ASP.NET Core compatible :)) for NLog.web 4.3 - it's already in master . See Update docs for Nlog.Web 4.3 NLog.Web#64
  2. move AspNetExtensions to nlog.web and remove ASP.NET dependency.
  3. release nlog.web 4.3 with dependency to NLog.Extensions.Logging (for .NET Core)
  4. remove AspNetExtensions from NLog.Extensions.Logging, update nuspec
  5. release NLog.Extensions.Logging (2.0?)

I could use some help on 1.

@304NotModified
Copy link
Member

working on this

@304NotModified
Copy link
Member

this has been released!

https://www.nuget.org/packages/NLog.Extensions.Logging/1.0.0-rtm-beta1

ASP.NET Core users should also install NLog.Web.AspNetCore: https://www.nuget.org/packages/NLog.web.aspnetcore

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants