>From: Jaroslaw Kowalski <
jaak@...>
>To: Ron Grabowski <
rongrabowski@...>
>CC:
nlog-list@...
>Subject: Re: [Nlog-list] newbie usage question
>Date: Tue, 18 Jul 2006 09:10:23 +0200
>MIME-Version: 1.0
>Received: from lists-outbound.sourceforge.net ([66.35.250.225]) by
>bay0-mc1-f11.bay0.hotmail.com with Microsoft SMTPSVC(6.0.3790.2444); Tue,
>18 Jul 2006 00:10:22 -0700
>Received: from sc8-sf-list2-new.sourceforge.net (unknown [10.3.1.94])by
>sc8-sf-spam2.sourceforge.net (Postfix) with ESMTPid 4DDCFF5F6; Tue, 18 Jul
>2006 00:10:21 -0700 (PDT)
>Received: from sc8-sf-mx2-b.sourceforge.net
>([10.3.1.92]helo=mail.sourceforge.net)by sc8-sf-list2-new.sourceforge.net
>with esmtp (Exim 4.43)id 1G2jil-0005lV-2Yfor
>
nlog-list@...; Tue, 18 Jul 2006 00:10:19 -0700
>Received: from host-20.noc.atman.pl ([217.149.245.20] helo=sav.net)by
>mail.sourceforge.net with esmtps (TLSv1:AES256-SHA:256)(Exim 4.44) id
>1G2jii-0002qU-SLfor
nlog-list@...; Tue, 18 Jul 2006
>00:10:19 -0700
>Received: from jaak.homedns.org ([10.56.0.2])by sav.net (8.13.6/8.13.4)
>with ESMTP id k6I7AAcH012930;Tue, 18 Jul 2006 09:10:10 +0200
>Received: from [10.25.0.2] ([10.25.0.2])by jaak.homedns.org (8.13.6/8.13.6)
>with ESMTP id k6I7Adal014530;Tue, 18 Jul 2006 09:10:39 +0200
>X-Message-Info: LsUYwwHHNt2e9tfe6S9C80/AQIUS1w264UFMlzXvcuE=
>User-Agent: Thunderbird 1.5.0.4 (Windows/20060516)
>References: <
20060718034343.34895.qmail@...>
>X-Spam-Score: 1.0 (+)
>X-Spam-Report: Spam Filtering performed by sourceforge.net.See
>
http://spamassassin.org/tag/ for more details.Report problems
>tohttp://sf.net/tracker/?func=add&group_id=1&atid=2000011.0
>FORGED_RCVD_HELO Received: contains a forged HELO
>X-BeenThere:
nlog-list@...
>X-Mailman-Version: 2.1.8
>Precedence: list
>List-Id: <nlog-list.lists.sourceforge.net>
>List-Unsubscribe:
><
https://lists.sourceforge.net/lists/listinfo/nlog-list>,<mailto:
nlog-list-request@...?subject=unsubscribe>
>List-Archive:
><
http://sourceforge.net/mailarchive/forum.php?forum=nlog-list>
>List-Post: <mailto:
nlog-list@...>
>List-Help: <mailto:
nlog-list-request@...?subject=help>
>List-Subscribe:
><
https://lists.sourceforge.net/lists/listinfo/nlog-list>,<mailto:
nlog-list-request@...?subject=subscribe>
>Errors-To:
nlog-list-bounces@...
>Return-Path:
nlog-list-bounces@...
>X-OriginalArrivalTime: 18 Jul 2006 07:10:23.0255 (UTC)
>FILETIME=[3C8FC270:01C6AA39]
>
>Ron Grabowski wrote:
> > It sounds like you want to associate different namespaces/projects
> > within the same process with different/independent logging
> > configurations. Log4net uses a construct called a Repository to
> > represent the different logging partitions in an application. By
> > default all applications have a single Repository (similiar to a
> > harddrive containing only one partition). Its sounds like you want to
> > parition your application to use a different logging configuration for
> > a particular part of the logging code in your process. This would be
> > akin to spliting a harddrive into two partitions. Here's more
> > information on Repositories:
> >
> >
http://logging.apache.org/log4net/release/manual/repositories.html> >
> > Is that what you want to do? If so, your application has advanced
> > logging requirements compared to most applications. Don't get
> > frustrated if things don't work the first time. Don't let my log4net
> > examples sway you from using NLog...I coudln't think of a real world
> > example of log4net's Repository design. NLog is very flexible and
> > should be able to handle your requirements.
> >
>How about allowing multiple instances of LogManager? Each would have its
>own configuration, loggers and so on. You'd have to create it manually
>but then you'd get a fully partitioned NLog configuration.
>
>I've just committed a class called "LogFactory" which is essentially a
>LogManager, but with all fields/properties turned into instance.
>LogManager was converted to use this new class internally while
>preserving its public static interface.
>
>Once we have this log factory class, you can build your own, private
>LogManager which holds a single instance of LogFactory (similar to
>singleton) very easily:
>
> internal class MyLogManager
> {
> public static read only LogFactory Instance
> = new LogFactory(new
>XmlLoggingConfiguration("c:\\path\\to\\NLog.config"));
> }
>
>Then create loggers with:
>
>Logger logger = MyLogManager.Instance.GetLogger("name");
>
>or
>
>Logger logger = MyLogManager.Instance.GetCurrentClassLogger();
>
>The loggers are independent from the ones created with NLog LogManager
>and thus you can have safe private logging. If you want multiple
>assemblies to share this MyLogManager - just make it a public class and
>get others to use it.
>
>You need to make sure that the configuration is properly closed when the
>process terminates (set MyLogManager.Instance.Configuration to null) or
>you may lose some log output.
>
>You may want to hook AppDomain.ProcessExit and AppDomain.DomainUnload
>events to turn off logging automatically. See the code:
>
>
http://svn.nlog-project.org/repos/nlog/trunk/NLog/src/NLog/LogManager.cs>
>This is available in the 20060718 snapshot.
>
>
http://www.nlog-project.org/snapshots/>
>Jarek
>
>
This sounds like exactly what I want; thank you!
To test my understanding, and to try to help
a tiny bit, I modified your write-up slightly to
try to make it a bit more FAQ-like:
---------------------------------
* How do I configure NLogging for a component?
If you can configure NLogging on the client-side, you can
follow the tutorial (which is oriented towards logging from
an application).
However, if you do not control the clients, or they are
not all local, or you wish a solution encapsulated to your
component or assembly, you may wish to configure NLogging
locally in your component assembly.
Create a log manager just for your component.
The following solution is usable for components not in the GAC.
(Components in the GAC need to implement
below method GetNLogConfigFilepath in some
application-dependent fashion.)
internal class MyLogManager
{
// A Logger dispenser for the current assembly
public static read only LogFactory Instance
= new LogFactory(
new XmlLoggingConfiguration(GetNLogConfigFilepath));
// Use a config file located next to our current assembly dll
// eg, if the running assembly is c:\path\to\MyComponent.dll
// the config filepath will be c:\path\to\MyComponent.dll.config
// WARNING: This will not be appropriate for assemblies in the GAC
private string GetNLogConfigFilepath()
{
// Use name of current assembly to construct NLog config filename
System.Reflection.Assembly thisAssembly
= System.Reflection.Assembly.GetExecutingAssembly();
string assempath = Path.GetDirectoryName(thisAssembly.CodeBase);
string configfile = thisAssembly.GetName().Name + ".NLog.config";
return assempath + "\\" + configfile;
}
}
Then create loggers with:
Logger logger = MyLogManager.Instance.GetLogger("name");
or
Logger logger = MyLogManager.Instance.GetCurrentClassLogger();
The loggers are independent from the ones created with NLog
LogManager, and thus you can have safe private logging. That is,
this will not interfere with other assemblies or the application
exe itself using NLog.
If you want multiple assemblies to share this MyLogManager -
just make it a public class and get others to use it.
You need to make sure that the configuration is properly
closed when the process terminates (set
MyLogManager.Instance.Configuration to null) or you may
lose some log output.
You may want to hook AppDomain.ProcessExit and
AppDomain.DomainUnload events to turn off logging automatically.
See the code:
http://svn.nlog-project.org/repos/nlog/trunk/NLog/src/NLog/LogManager.csThis is available in the 20060718 snapshot.
http://www.nlog-project.org/snapshots/-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV_______________________________________________
Nlog-list mailing list
Nlog-list@...
https://lists.sourceforge.net/lists/listinfo/nlog-list