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

Error when deploy web with NLog.Web.AspNetCore on IIS #229

Closed
joscalv opened this issue Dec 4, 2017 · 11 comments
Closed

Error when deploy web with NLog.Web.AspNetCore on IIS #229

joscalv opened this issue Dec 4, 2017 · 11 comments

Comments

@joscalv
Copy link

joscalv commented Dec 4, 2017

Hi All,

I have develop a test and use the example "ASP.NET Core 2 - VS2017" of the repo, to use Nlog in ASP .Net Core, using the package NLog.Web.AspNetCore rc1, but when I execute the solution over IIS instead IIS Express the solutions stops without throw an exception.

The software fails in this line:

var logger = NLogBuilder.ConfigureNLog("NLog.config").GetCurrentClassLogger();  

Thanks!

@304NotModified
Copy link
Member

I think there should be an exception, but it's very high level.

Could you check the internal log? https://github.com/NLog/NLog/wiki/Internal-logging

@joscalv
Copy link
Author

joscalv commented Dec 4, 2017

I have activated the trace level and this is the result.
Regarding the dependencies, I have the NLog 4.5.0-rc2 and Nlog.Web.AspNetCore 4.5.0-rc1
The most weird is that in IIS express works and in IIS not...

2017-12-04 16:43:35.0488 Trace Scanning LevelLayoutRenderer 'Layout Renderer: ${level}'
2017-12-04 16:43:35.0488 Trace FindReachableObject<NLog.Internal.IRenderable>:
2017-12-04 16:43:35.0488 Trace Scanning LoggerNameLayoutRenderer 'Layout Renderer: ${logger}'
2017-12-04 16:43:35.0488 Trace FindReachableObject<NLog.Internal.IRenderable>:
2017-12-04 16:43:35.0650 Trace Scanning MessageLayoutRenderer 'Layout Renderer: ${message}'
2017-12-04 16:43:35.0650 Debug Setting 'NullTarget.name' to 'blackhole'
2017-12-04 16:43:35.0650 Info Adding target Null Target[blackhole]
2017-12-04 16:43:35.0650 Debug Registering target blackhole: NLog.Targets.NullTarget
2017-12-04 16:43:35.0650 Trace ParseRulesElement
2017-12-04 16:43:35.0650 Info Configured from an XML element in NLog.config...
2017-12-04 16:43:35.1001 Debug Unused target checking is started... Rule Count: 3, Target Count: 3
2017-12-04 16:43:35.1001 Debug Unused target checking is completed. Total Rule Count: 3, Total Target Count: 3, Unused Target Count: 0
2017-12-04 16:43:35.1001 Debug Registering NLog.Web.AspNetCore
2017-12-04 16:43:35.1001 Debug ScanAssembly('NLog.Web.AspNetCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c')
2017-12-04 16:43:35.3450 Info Shutting down logging...
2017-12-04 16:43:35.3490 Info Logger has been shut down.

@joscalv
Copy link
Author

joscalv commented Dec 5, 2017

Hi,

I have debugged the error. The program stops when:

LogManager.AddHiddenAssembly(Assembly.Load(new AssemblyName("Microsoft.Extensions.Logging")));

The whole class is:

private static void ConfigureHiddenAssemblies()
        {
            //ignore this
            LogManager.AddHiddenAssembly(Assembly.Load(new AssemblyName("Microsoft.Extensions.Logging")));
            LogManager.AddHiddenAssembly(Assembly.Load(new AssemblyName("Microsoft.Extensions.Logging.Abstractions")));

            try
            {
                //try the Filter ext
                var filterAssembly = Assembly.Load(new AssemblyName("Microsoft.Extensions.Logging.Filter"));
                LogManager.AddHiddenAssembly(filterAssembly);
            }
            catch (Exception)
            {
                //ignore
            }

            LogManager.AddHiddenAssembly(typeof(ConfigureExtensions).GetTypeInfo().Assembly);
        }
    }

Any idea about how to solve it?

@304NotModified
Copy link
Member

there should be an exception. Please use the debugger of Visual Studio.

@joscalv
Copy link
Author

joscalv commented Dec 5, 2017

The problem is a dependency on "Microsoft.Extensions.Logging.Filter". I have added it manually using nuget and it works, but I don't understand the reason...

The line which the exception thows is :
LogManager.AddHiddenAssembly(Assembly.Load(new AssemblyName("Microsoft.Extensions.Logging")));

@304NotModified
Copy link
Member

is there no Microsoft.Extensions.Logging dll in your project?

@304NotModified
Copy link
Member

there should be a strack trace and exception title/message.

see https://stackoverflow.com/questions/116896/visual-studio-how-to-break-on-handled-exceptions

@joscalv
Copy link
Author

joscalv commented Dec 5, 2017

I havent a explicit reference to Microsoft.Extensions.Logging. But I in some coworkers pcs it works without it. The same happen with the example of github, so I supposed that I have something wrong in my installation of .net Core.
I will check how to trace the exception.
Thanks

@snakefoot
Copy link
Contributor

snakefoot commented Dec 5, 2017

@304NotModified Guess a helper method could be made, then one would also get better exception logging:


private static void ConfigureHiddenAssemblies()
{
            SafeAddHiddenAssembly("Microsoft.Extensions.Logging");
            SafeAddHiddenAssembly("Microsoft.Extensions.Logging.Abstractions");
            SafeAddHiddenAssembly("Microsoft.Extensions.Logging.Filter");

            LogManager.AddHiddenAssembly(typeof(ConfigureExtensions).GetTypeInfo().Assembly);
}

static void SafeAddHiddenAssembly(string assemblyName)
{
   try
   {
          var assembly = Assembly.Load(new AssemblyName(assemblyName));
          LogManager.AddHiddenAssembly(assembly);
   }
   catch (Exception ex)
   {
       // Do some logging
   }
}

But it is probably a bug in the nuget-package cache @joscalv

@304NotModified
Copy link
Member

@snakefoot yes I think this is needed, thx for the snippet!

@304NotModified
Copy link
Member

A more robust way of hiding the assembles has been added to rc2

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

No branches or pull requests

3 participants