Confluent-kafka-dotnet: Where do I view output of logs?

Created on 5 Apr 2017  路  8Comments  路  Source: confluentinc/confluent-kafka-dotnet

I have created a Producer application and this is how the producer is configured.

var config = new Dictionary<string, object>()
{
                    {"bootstrap.servers", _brokerUrl},
                    {"client.id", "TEST.001"},
                    {"debug", "protocol"}
}
var producer = new Producer<string, string>(config, new StringSerializer(Encoding.UTF8), new StringSerializer(Encoding.UTF8));

var producerTask = _producer.ProduceAsync("TEST.Topic.001", "100", "500");
var result = producerTask.Result;

When I set the {"debug", "protocol"}, I was expecting to see some log outputs from Confluent.Kafka .net client / librdkafka. My test producer application is a standard windows .net console app. I can see the output from my own statements such as Console.WriteLine and if I am using a debug viewer, I can view output of my own Debug.WriteLine statements.

Just wondering, when I set {"debug", "protocol"}, where is the log output from Confluent.Kafka .net client / librdkafka recorded on the client machine? My test producer client console application is running on Windows 7, where as the Kafka server is running on a remote Linux server.

I am trying to create a test producer using c#, .NET 4.6.1 and I am using Confluent.Kafka 0.9.4, librdkafka.redist 0.9.4.

question

Most helpful comment

I found the issue, it was on my side. I was prematurely disposing the Producer. As this issue was occurring only when {"debug", "protocol"} is used, I thought it may have to do something with OnLog. I now identified the source of that error and it is working without any issues.

All 8 comments

There is a bug with the serializing producer (see #134), you have to register to the OnLog event to see the logs (producer.OnLog += Loggers.ConsoleLogger should work to log to console, you can write your own implementation)

That did the trick. Thank you for the suggestion. Both options worked.

producer.OnLog += Loggers.ConsoleLogger;

OR

producer.OnLog += OnProducerLog;

private void OnProducerLog(object sender, LogMessage e)
{
            //log4net
            Log.Debug($"ConfluentKafka : [{e.Name}] [{e.Facility}] [{ e.Level}] [{e.Message}]");
}

Every time I enable debug = protocol, I am now able to capture the logs except that at the end, I see following error "Unhandled Exception: System.AppDomainUnloadedException: Attempted to access an unloaded AppDomain.", is this the bug you are referring to?

The AppDomainUnloadedException here is something I haven't seen before.

I believe the bug @treziac was referring to is the need to register a log handler to see the messages (changed in master).

Are you disposing the Producer before exiting?

I was referring to the logging only, never saw this error either.
Could you post your complete code?

Sure, I will gather the important parts and post it soon.

I found the issue, it was on my side. I was prematurely disposing the Producer. As this issue was occurring only when {"debug", "protocol"} is used, I thought it may have to do something with OnLog. I now identified the source of that error and it is working without any issues.

perhaps it's possible to do something better with throwing exceptions here, but I'll close this as too low priority to worry about for now. If we see this repeatedly come up again we might re-consider.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MihaiComan87 picture MihaiComan87  路  3Comments

alfhv picture alfhv  路  3Comments

kvandake picture kvandake  路  3Comments

Duorman picture Duorman  路  3Comments

farodin91 picture farodin91  路  3Comments