orleans icon indicating copy to clipboard operation
orleans copied to clipboard

Could not add NLog provider to Orleans(2.0 beta1) logging ?

Open bluexo opened this issue 9 years ago • 5 comments

How to use NLog with orleans (2.0 beta1) logging ? When I use NLog for client , its working well , but when I use it for SiloHost , it does not output anything , Why ? cannot add 3rd logging provider ? this is my code :

using NLog.Extensions.Logging;

 var builder = new SiloHostBuilder()
                .UseConfiguration(config)
                .AddApplicationPartsFromBasePath()
                .ConfigureLogging(logging =>
                {
                    logging.AddNLog(new NLogProviderOptions { CaptureMessageTemplates = true, CaptureMessageProperties = true });
                    //logging.AddConsole();
                });

bluexo avatar Nov 06 '17 14:11 bluexo

SiloHost should be able to add 3rd party logging provider. I personally tested start up a silo with a 3rd party logger configured. And I see log messages produced. But I haven't tried NLog yet. Let me give it a go, with the code sample in your description, and see.

xiazen avatar Nov 07 '17 22:11 xiazen

I'm confused on this line logging.AddNLog(new NLogProviderOptions { CaptureMessageTemplates = true, CaptureMessageProperties = true });

AFSIK NLog only have AddNLog extension method on ILoggerFactory, not ILoggingBuilder. while ConfigureLogging method take a ILoggerBuilder. So I doubt this line compiles.

And also, how do you configure the targets for NLog?

xiazen avatar Nov 07 '17 23:11 xiazen

Since NLog doesn't have extension methods on ILoggingBuilder, so I went back to older ways of configuring MEL logging, which is through ILoggerFactory

I used the code sample as follows

new SiloHostBuilder()
                   .ConfigureSiloName(siloName)
                   .UseConfiguration(clusterConfiguration)
                   .UseGrainBasedMembership()
                   .ConfigureServices(services =>
                   {
                       var loggerFactory = new LoggerFactory();
                       loggerFactory.AddNLog(new NLogProviderOptions { CaptureMessageTemplates = true, CaptureMessageProperties = true });
                       loggerFactory.ConfigureNLog("nlog.config");
                       services.TryAddSingleton<ILoggerFactory>(loggerFactory);
                   });

I configured one file target through nlog.config. It logged as normal. Hope this helps

xiazen avatar Nov 07 '17 23:11 xiazen

@xiazen I use this NLog extensions , it has ILoggingBuilder.AddNLog() https://github.com/NLog/NLog.Extensions.Logging

bluexo avatar Nov 08 '17 00:11 bluexo

I tried using the ILoggingBuilder in NLog.Extensions but I couldn't see how to change the NLog configuration using that class. So I use @xiazen's technique

zhulika avatar Jan 01 '18 18:01 zhulika