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();
});
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.
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?
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 I use this NLog extensions , it has ILoggingBuilder.AddNLog() https://github.com/NLog/NLog.Extensions.Logging
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
Most helpful comment
Since NLog doesn't have extension methods on
ILoggingBuilder, so I went back to older ways of configuring MEL logging, which is throughILoggerFactoryI 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