bozoid
bozoid

Reputation: 11

.Net/Mono & Ubuntu versus log4net

I've been asked to write a small instrument-calibration app on Ubuntu Linux (14.04) and have been writing some small proof-of-concept apps (serial i/o, GUI, SQLite, etc.) to see if Mono is a good fit. Things were going well until I tested log4net, my favorite logging package. I cannot get the code to work. Here's a simple test app that works fine on a Windows box:

using System;
using log4net;
using log4net.Config;

public class L
{
    public static void Main(string[] args)
    {
        Console.WriteLine("Version: " + Environment.Version);
        XmlConfigurator.Configure(
            new System.IO.FileInfo("console.logconfig.xml"));
        Console.WriteLine("logging configured.");
        ILog log = LogManager.GetLogger("root");
        log.Info("This is an info message.");
        log.Warn("This is a warning message.");
        log.Error("This is an error message.");
    }
}

Compiled with

gmcs -pkg:log4net,dotnet -main:L -out:L.exe L.cs

the code compiles, but generates a runtime error:

Version: 2.0.50727.1433
Missing method System.Reflection.Assembly::op_Equality(Assembly,Assembly) in assembly /usr/lib/mono/2.0/mscorlib.dll, referenced in assembly /usr/lib/mono/gac/log4net/1.2.10.0__a5715cc6d5c3540b/log4net.dll

Unhandled Exception:
System.MissingMethodException: Method not found: 'System.Reflection.Assembly.op_Equality'.
  at log4net.LogManager.GetRepository (System.Reflection.Assembly repositoryAssembly) [0x00000] in <filename unknown>:0
  at log4net.Config.XmlConfigurator.Configure (System.IO.FileInfo configFile) [0x00000] in <filename unknown>:0
  at L.Main (System.String[] args) [0x00000] in <filename unknown>:0

This looks like a .Net version mismatch (maybe op_equality wasn't available in .Net 2.0?). When I try to force version 4 or 4.5 of the SDK:

gmcs -sdk:4.5 -pkg:log4n35,dotnet -main:L -out:L.exe L.cs

I get a compile error:

error CS0006: Metadata file `cscompmgd.dll' could not be found

This is on a brand-new Ubuntu 14.04 VM with Mono installed via:

sudo apt-get install mono-complete
sudo apt-get install liblog4net1.2-cil
sudo apt-get install liblog4net-cil-dev

Recommendations, please?

Upvotes: 1

Views: 1460

Answers (2)

bob coco
bob coco

Reputation: 1

You almost had it; Ubuntu 14.04:

gmcs -sdk:4.5 -r:/usr/lib/cli/log4net-1.2/log4net.dll App.cs

Upvotes: 0

user4524982
user4524982

Reputation:

Unfortunately the version of log4net packaged for Ubuntu (1.2.10) is pretty old and known to have problems with .NET 4.0. 1.2.11 has been released in October 2011 and as of this writing 1.2.13 is the latest release.

You need to download the latest version from the Apache log4net site directly: http://logging.apache.org/log4net/download_log4net.cgi

Upvotes: 1

Related Questions