NLog with silverlight on RC1

25 views
Skip to first unread message

Marwijn

unread,
Dec 1, 2011, 5:33:20 AM12/1/11
to Castle Project Development List
Hello All,

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));

Krzysztof Koźmic

unread,
Dec 1, 2011, 6:04:39 AM12/1/11
to castle-pro...@googlegroups.com
can you send a pull request?


K

Marwijn

unread,
Dec 1, 2011, 12:20:01 PM12/1/11
to Castle Project Development List
Hello Kryzsztof,

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.

Reply all
Reply to author
Forward
0 new messages