Instead of using the GlobalContext.Properties to define where your logs are coming from I would define a Shared/Static logger per class based on the fully qualified class name allowing you to use the logger hierarchy as defined here http://logging.apache.org/log4net/release/manual/introduction.html
The FAQ has a section too... http://logging.apache.org/log4net/release/faq.html#Implementing%20Logging This way you can turn off specific loggers, direct them to different appenders, ... Mike On Wed, Sep 2, 2009 at 9:01 AM, mattyboy<[email protected]> wrote: > > Thanks for the replying. > > When I say mutliple assemblies I have a GUI app. and it uses log4net to log > to a file let's say 'C:\Claymore.log'. > > I have developed several .dll files which I call from within the GUI app. I > want the code within the .dll files to also log to 'C:\Calymore.log'. > > I've actually just managed to get it working but I'm not using locking and > wonder whether I should be or not for this scenario. As far as I'm aware > everything will run in the same process and should be fine without > locking......? > > Here's what I've done: > > In both the GUI front-end and each .dll I have added the following entry to > the AssemblyInfo.vb (yes, I'm using vb.net!) file > > <Assembly: > log4net.Config.XMLConfigurator(ConfigFile:="Claymore.exe.log4net", > Watch:=True)> > > In GUI Front-End Assembly ONLY I've added 'Claymore.exe.log4net' file. > > Then in GUI Front-End class: > > Public Class frmDashboard > Public Shared logger As log4net.ILog > > Private Sub frmDashboard_Load(ByVal sender As Object, ByVal e As > System.EventArgs) Handles Me.Load > log4net.GlobalContext.Properties("AssemblyName") = > Assembly.GetExecutingAssembly.GetName.Name() > logger = log4net.LogManager.GetLogger("ClaymoreLogger") > logger.Info("Dashboard_Load() - Start") > logger.Debug("Dashboard_Load() - Finish") > Dim clsGUI As New ClaymoreGUI.clsDashboard() > End Sub > End Class > > In my ClaymoreGUI.dll: > > Public Class clsDashboard > Public Shared logger As log4net.ILog > > Public Sub New() > log4net.GlobalContext.Properties("AssemblyName") = > Assembly.GetExecutingAssembly.GetName.Name() > logger = log4net.LogManager.GetLogger("ClaymoreLogger") > logger.Info("New() - Start") > logger.Debug("New() - Finish") > End Sub > End Class > > Seems to work well :-) > > > > Michael Schall wrote: >> >> When you say multiple assemblies, I assume you mean multiple >> processes? Logging this way is not suggested as for each log message >> you have to reopen the file. If you have really light logging, it >> would probably be ok... >> >> Look at the LockingModel: >> http://logging.apache.org/log4net/release/sdk/log4net.Appender.FileAppender.LockingModel.html >> >> From http://logging.apache.org/log4net/release/config-examples.html: >> >> This example shows how to configure the appender to use the minimal >> locking model that allows multiple processes to write to the same >> file. >> >> <appender name="FileAppender" type="log4net.Appender.FileAppender"> >> <file value="${TMP}\log-file.txt" /> >> <appendToFile value="true" /> >> <lockingModel type="log4net.Appender.FileAppender+MinimalLock" /> >> <layout type="log4net.Layout.PatternLayout"> >> <conversionPattern value="%date [%thread] %-5level %logger >> [%property{NDC}] - %message%newline" /> >> </layout> >> </appender> >> >> On Wed, Sep 2, 2009 at 3:28 AM, mattyboy<[email protected]> >> wrote: >>> >>> Hi Christian, >>> >>> I'm actually looking to achieve the opposite, I want to know if it's >>> possible to get several assemblies to log to the SAME log file. Have you >>> managed to achieve this? If so, do you have any example code/configs >>> etc.? >>> >>> Many Thanks >>> >>> >>> cristianmad wrote: >>>> >>>> Hi, >>>> >>>> I am new to log4net and just starting reading some documentation about >>>> it. >>>> We need to see if it would be a suitable logging solution for our >>>> applications. >>>> Our product (like most of them) uses a number of assemblies. I was >>>> wondering if it would be possible for each assembly to log in its own >>>> log >>>> file (or any other destination) even if they are loaded in the same >>>> application domain. >>>> For example consider we have the following assemblies: A.dll and B.dll. >>>> Is >>>> it possible for the two assemblies to log in their own log files even if >>>> they are loaded in the same application domain? >>>> If yes, could you please give me a very simple example? >>>> >>>> >>>> Thank you, >>>> Cristian >>>> >>> >>> -- >>> View this message in context: >>> http://www.nabble.com/Log-in-more-than-1-log-destination-for-different-assemblies.-tp24807634p25253548.html >>> Sent from the Log4net - Users mailing list archive at Nabble.com. >>> >>> >> >> > :-):-):-) > -- > View this message in context: > http://www.nabble.com/Log-in-more-than-1-log-destination-for-different-assemblies.-tp24807634p25258147.html > Sent from the Log4net - Users mailing list archive at Nabble.com. > >
