Implementation of .netcore ILogger for Azure Event Hub
Install the Daenet.Common.Logging.EventHub NuGet Package in your application.
Following code block, shows how to add EventHubLogger provider to the loggerFactory in EventHubLoggerUnitTests class:
private void initializeEventHubLogger(Func<string, LogLevel, bool> filter,
Func<LogLevel, EventId, object, Exception, EventData> eventDataFormatter = null,
Dictionary<string, object> additionalValues = null)
{
ConfigurationBuilder cfgBuilder = new ConfigurationBuilder();
cfgBuilder.AddJsonFile(@"EventHubLoggerSettings.json");
var configRoot = cfgBuilder.Build();
ILoggerFactory loggerFactory = new LoggerFactory()
.AddEventHub(configRoot.GetEventHubLoggerSettings(), filter, eventDataFormatter, additionalValues);
m_Logger = loggerFactory.CreateLogger<EventHubLoggerUnitTests>();
}
Following configuration needs to be added in the EventHubLogger>settings.json file.