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

Possible Issues with Common.Logging / Common.Logging.NLog20 NuGet packages #23

Closed
peterbernier opened this issue Feb 12, 2013 · 9 comments

Comments

@peterbernier
Copy link

I think there may be an error in the information added to web.config when the indicated NuGet packages are added to a project.

When the package is added to the project, the following is added to web.config:

    <dependentAssembly>
      <assemblyIdentity name="Common.Logging" publicKeyToken="af08829b84f0328e" culture="neutral" />
      <bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
    </dependentAssembly>

Unfortunately this seems to result in the following error at run-time :

Parser Error Message: An error occurred creating the configuration section handler for common/logging: Unable to create type 'Common.Logging.NLog.NLogLoggerFactoryAdapter, Common.Logging.NLog20'

I had to make the following change in order to resolve the issue (note the 'oldVersion' attribute)...

    <dependentAssembly>
       <assemblyIdentity name="Common.Logging" publicKeyToken="af08829b84f0328e" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="2.0.0.0" />
      </dependentAssembly>
@peteraritchie
Copy link

I created a new MVC 4 Razer web application, added the Common.logging.NLog20 package (which installed the Common.Logging dependency) and did not have this problem.

I then added the folllowing to the configSections in web.config:
<section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/>

and added a nlog section with some arbitrary config:
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <targets> <target name="logfile" xsi:type="file" filename="e:\logfile.txt" layout="${date:format=yyyy/MM/dd HH:mm:ss} ${message}" /> </targets> <rules> <logger name="*" minlevel="Trace" writeTo="logfile" /> </rules> </nlog>

and I still couldn't reproduce what you've described. Is there any more detail you can provide?

@peterbernier
Copy link
Author

Hi Peter,

Here's some more detailed STR what I'm seeing... I seem to be getting a slightly different error message when I use a simpler logger configuration, but the 'fix' is the same.

  • Create a new Asp.net MVC 4 Web Application (Basic, Razor)
  • Create a Home controller at Controllers\HomeController.cs
  • Create a view at Views/Home/Index.
  • Run the project in debug mode, observe that the view created is displayed properly.
  • Stop debugging, Select the Project, right-click and select Manage NuGet Packages
  • Select 'Online' results on the left, search for 'nlog2'
  • Select 'Common.Logging.NLog20' package, click 'Install'. This will install the Common.Logging and NLog dependencies as well. Close the NuGet Package Manager dialog.
  • In the project, Observe that references to Common.Logging, Common.Logging.NLog20, and NLog have been created
  • open Controllers\HomeController.cs
  • add
    using Common.Logging;
  • Modify the Index method to include the following lines before return statement:
    ILog log = LogManager.GetCurrentClassLogger();
    log.Debug("hello world");
  • Open web.config
  • Observe that the assemblyBinding entry (near the end of the file) contains the lines below

    <dependentAssembly>
    <assemblyIdentity name="Common.Logging" publicKeyToken="af08829b84f0328e" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
    </dependentAssembly>
  • Update web.config with the contents below (as per http://netcommon.sourceforge.net/docs/2.1.0/reference/html/ch01.html)
    <configuration>
    <configSections>
        <sectionGroup name="common">
            <section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
        </sectionGroup>
        <section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/>
    </configSections>
    <common>
        <logging>
            <factoryAdapter type="Common.Logging.NLog.NLogLoggerFactoryAdapter, Common.Logging.NLog20">
                <arg key="configType" value="INLINE" />
            </factoryAdapter>
        </logging>
    </common>
    <nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <targets>
            <target name="logfile" xsi:type="file" filename="E:\logfile.txt" layout="${date:format=yyyy/MM/dd HH:mm:ss} ${message}" />
        </targets>
        <rules>
            <logger name="*" minlevel="Trace" writeTo="logfile" />
        </rules>
    </nlog>
    </configuration>
  • Run the project in Debug mode, observe the error thrown:

Failed obtaining configuration for Common.Logging from configuration section 'common/logging'.

  • open web.config, at the bottom on the file, update the bindingRedirect node for Common.Logging

    <dependentAssembly>
    <assemblyIdentity name="Common.Logging" publicKeyToken="af08829b84f0328e" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="2.0.0.0" />
    </dependentAssembly>
  • Run the project in Debug mode, observe that no errors are thrown. Observe that messages are written to the log appropriately.

@fernandoacorreia
Copy link

The same error happened to me. Steps to reproduce:

  1. Open Visual Studio 2012.
  2. File | New | Project, ASP.NET MVC 4 Web Application, Internet Application.
  3. Tools | Library Package Manager | Manage NuGet Packages for Solution.
  4. Install Common.Logging.NLog20, OK.
  5. Edit Web.config:
<configSections>
    (...)
    <sectionGroup name="common">
        <section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
    </sectionGroup>
    <section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/>
</configSections>
<common>
    <logging>
        <factoryAdapter type="Common.Logging.NLog.NLogLoggerFactoryAdapter, Common.Logging.NLog20">
            <arg key="configType" value="INLINE" />
        </factoryAdapter>
    </logging>
</common>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <targets>
        <target name="console" xsi:type="Console" layout="${date:format=HH\:MM\:ss} ${logger} ${message}" />
    </targets>
    <rules>
        <logger name="*" minlevel="Debug" writeTo="console" />
    </rules>
</nlog>
  1. Edit HomeController.cs:
    public class HomeController : Controller
    {
        private ILog log = LogManager.GetCurrentClassLogger();

        public ActionResult Index()
        (...)
  1. Run project in debug mode.
  2. This error is shown in the response page:
Server Error in '/' Application.

Configuration Error

Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately. 

Parser Error Message: An error occurred creating the configuration section handler for common/logging: Unable to create type 'Common.Logging.NLog.NLogLoggerFactoryAdapter, Common.Logging.NLog20'

Source Error: 


Line 14:   </configSections>
Line 15:   <common>
Line 16:     <logging>
Line 17:       <factoryAdapter type="Common.Logging.NLog.NLogLoggerFactoryAdapter, Common.Logging.NLog20">
Line 18:         <arg key="configType" value="INLINE" />

Source File: C:\Users\user.name\Documents\Projetos\Rascunhos\MvcApplication1\MvcApplication1\web.config    Line: 16 

Assembly Load Trace: The following information can be helpful to determine why the assembly 'Common.Logging, Version=2.1.2.0, Culture=neutral, PublicKeyToken=af08829b84f0328e' could not be loaded.


=== Pre-bind state information ===
LOG: User = DOMAIN\user.name
LOG: DisplayName = Common.Logging, Version=2.1.2.0, Culture=neutral, PublicKeyToken=af08829b84f0328e
 (Fully-specified)
LOG: Appbase = file:///C:/Users/user.name/Documents/Projetos/Rascunhos/MvcApplication1/MvcApplication1/
LOG: Initial PrivatePath = C:\Users\user.name\Documents\Projetos\Rascunhos\MvcApplication1\MvcApplication1\bin
Calling assembly : Common.Logging.NLog20, Version=2.1.2.0, Culture=neutral, PublicKeyToken=af08829b84f0328e.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\user.name\Documents\Projetos\Rascunhos\MvcApplication1\MvcApplication1\web.config
LOG: Using host configuration file: C:\Users\user.name\Documents\IISExpress\config\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: Common.Logging, Version=2.1.2.0, Culture=neutral, PublicKeyToken=af08829b84f0328e
LOG: Attempting download of new URL file:///C:/Users/user.name/AppData/Local/Temp/Temporary ASP.NET Files/root/0af0b8d1/2ac424b/Common.Logging.DLL.
LOG: Attempting download of new URL file:///C:/Users/user.name/AppData/Local/Temp/Temporary ASP.NET Files/root/0af0b8d1/2ac424b/Common.Logging/Common.Logging.DLL.
LOG: Attempting download of new URL file:///C:/Users/user.name/Documents/Projetos/Rascunhos/MvcApplication1/MvcApplication1/bin/Common.Logging.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Minor Version
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18033

See also: http://stackoverflow.com/questions/14840445/how-can-i-successfully-configure-common-logging

@skalinkin
Copy link

The problem is in a NuGet package spec you have dependencies [dependency id="Common.Logging" version="2.0.0" ]
But actual dll references to 2.1.2.0
To workaround update Common.Logging through package manager. To fix that guys need to republish nuget package with proper reference.

@katlimruiz
Copy link

To me the fix is in the nuget package as well, but why it doesnt include the NET4 assembly?

It seems only to include NET2.0.

UPDATE: I confirm skalinkin solution is the fix.

@npehrsson
Copy link

Anything happening with this? Its quite annoying

@joshgo
Copy link

joshgo commented Dec 3, 2013

@skalinkin is right, updating Common.Logging to v2.1.2 will fix this.

It's annoying, but once you pull down the correct package and set auto-restore ... you won't have to think about it.

@dengere
Copy link

dengere commented Jul 21, 2014

do we select this for log or landing spaceship to mars? please fix issues and left clarified sample. what a nice standart! common.logging! blah blah blah

@sbohlen
Copy link
Member

sbohlen commented Oct 27, 2014

Closed as fixed with update to Common.Logging 2.1.2

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

No branches or pull requests

9 participants