jjchiw / gelf4net

GELF log4net Appender - graylog2
MIT License
63 stars 59 forks source link

Inheritance from assembly Gelf4Net from nuget. #41

Closed eseneckiy closed 5 years ago

eseneckiy commented 8 years ago

Hello! When I try to inherit from GelfAmqpAppender class I receive an error: Argument 1: cannot convert from 'RabbitMQ.Client.IConnection [..\packages\Gelf4Net.2.0.3.16\lib\net40\Gelf4Net.dll]' to 'RabbitMQ.Client.IConnection [..\packages\RabbitMQ.Client.3.6.4\lib\net45\RabbitMQ.Client.dll]'

Error appears only when I use package from nuget, if I build assembly from source code - everything is ok. Is it because RabbitMQ is merged into your assembly, am I right?

Thank you for gelf4net.

jjchiw commented 8 years ago

Hi

Yes I the problem is the version of RabbitMQ that it's merged in the assembly that has been instantiated to another client version, it's weird because even the client different version gelf4net will only use the internal connection.... Can you paste the code that it's throwing the error...

eseneckiy commented 8 years ago
using gelf4net.Appender;
using RabbitMQ.Client;
using System;
using System.Collections.Generic;

namespace CancelServer.Classes.Log
{
    public sealed class GelfAmqpMultiConnectAppender : GelfAmqpAppender
    {
        private List<Tuple<IConnection, IModel>> _connections { get; set; }

        public GelfAmqpMultiConnectAppender()
            : base()
        {
            _connections = new List<Tuple<IConnection, IModel>>();
        }

        public override void ActivateOptions()
        {
            base.ActivateOptions();
            AddConnection(Connection, Channel);

            var connection = ConnectionFactory.CreateConnection();
        }

        private void AddConnection(IConnection connection, IModel channel)
        {
            _connections.Add(new Tuple<IConnection, IModel>(connection, channel));
        }
    }
}

There is compilation time errors:

Argument 1: cannot convert from 'RabbitMQ.Client.IConnection [D:\Projects\CS\packages\Gelf4Net.2.0.3.16\lib\net40\Gelf4Net.dll]' to 'RabbitMQ.Client.IConnection [D:\Projects\CS\packages\RabbitMQ.Client.3.6.4\lib\net45\RabbitMQ.Client.dll]'

Argument 2: cannot convert from 'RabbitMQ.Client.IModel [D:\Projects\CS\packages\Gelf4Net.2.0.3.16\lib\net40\Gelf4Net.dll]' to 'RabbitMQ.Client.IModel [D:\Projects\CS\packages\RabbitMQ.Client.3.6.4\lib\net45\RabbitMQ.Client.dll]'

Error   CS0122  'ConnectionFactory.CreateConnection()' is inaccessible due to its protection level

Might be you should add RabbitMQ as dependent assembly in nuget package?
jjchiw commented 8 years ago

Thanks, I'll check during the weekend how to solve this issue...