I've tried to use NLog with silverlight. This works with some minor
(IMHO) changes (see below) to allow creating a NLogFactory with a
Configuration instead of config file (as reading file is not supported
in silverlight). If this change is not to big, risky or plain wrong,
could it be incorperated in v3 ?
Kind regards,
Marwijn.
In NLogFactory (probably same/similair change should be made in the
extended nlog factory):
Added additional constructor:
public MyNLogFactory(LoggingConfiguration configuration)
{
LogManager.Configuration = configuration;
}
in LoggingFacility:
Added
private ILoggerFactory loggerFactory;
public MyLoggingFacility
LogUsing<TCustomLoggerFactory>(TCustomLoggerFactory loggerFactory)
where TCustomLoggerFactory : ILoggerFactory
{
loggerImplementation = LoggerImplementation.Custom;
this.loggerFactory = loggerFactory;
return this;
}
Changed
protected override void Init()
{
SetUpTypeConverter();
if (loggerFactory == null) // Added null check to see the
user has provided it's own LoggerFactory
{
loggerFactory =
ReadConfigurationAndCreateLoggerFactory();
}
RegisterLoggerFactory(loggerFactory);
RegisterDefaultILogger(loggerFactory);
RegisterSubResolver(loggerFactory);
}
Usage example:
LoggingConfiguration config = new LoggingConfiguration();
var debugTarget = new NLog.Targets.
config.AddTarget("console", debugTarget);
config.LoggingRules.Add(new LoggingRule("*", NLog.LogLevel.Info,
debugTarget));
var logFactory = new NLogFactory(config);
var logger = logFactory.Create("Bootstrapper");
_container.AddFacility(new LoggingFacility().LogUsing(logFactory));
K
I'm new with github but I've tried to make 2 pull request, 1 for
windsor, 1 for core.
If they are not ok just let me know.
Marwijn.