Bill,

The DB appender param config is working for me here. How about we try something 
a little simpler. What happens if you use the following appender as well:

<appender name="Appender_WithHostName" type="log4net.Appender.TraceAppender">
  <layout 
    type="log4net.Layout.PatternLayout" 
    value="%date [%property{log4net:HostName}] - %message%newline" />
</appender> 

If you run your app in the debugger then this log output should go to the 
Output window in the debugger.

You can also enable log4net internal debug which will display any errors that 
are encountered during configuration. Add the following app setting entry to 
your app's .config file:

<appSettings>
  <add key="log4net.Internal.Debug" value="true"/>
</appSettings>


> You mentioned about permissions causing problems.  Is there 
> anything I can check?  I am running the unit tests both from 
> NAnt and from the Console, both of which I would assume are 
> running under my account which is set up as local administrator.

Then you should have no problem. There can be security issues if you are 
running from a network share, substed drive, or over the web.


> BTW, Is there any documentation on what properties are 
> available by default?
> I saw some mention of the log4net:HostName property in the 
> SDK, but that was it.

%property{log4net:HostName} is the only built-in global property. As always 
documentation could be improved.


> BTW2, You give an example of setting a property in Code, is 
> it possible to set it in the machine.config file, or at least 
> the app.config file rather than in code? (apologies if that's 
> a dumb question)

There is no built-in mechanism to do this. However it should not be too much 
trouble to do this for static strings by writing a custom .NET config parser 
that sets GlobalContext.Properties. To extend this to support layout patterns 
would be a reasonable amount of work, but this could be done with a log4net 
plugin configured in the log4net config file.

To be honest if you want to do something simple like load an identifier from 
the config file and store it in a well known global context property it would 
be easiest to just set that up programmatically, i.e.

log4net.GlobalContext.Properties["AppID"] = 
System.Configuration.ConfigurationSettings.AppSettings["MyApp.AppID"];

Nicko



> 
> Thanks for the help,
> 
> Bill
> 
>  -----Original Message-----
> From:         Nicko Cadell [mailto:[EMAIL PROTECTED] 
> Sent: 22 April 2005 19:53
> To:   Log4NET User
> Subject:      RE: Machine name
> 
> Bill,
> 
> Long pattern names like %property require version 1.2.9. Can 
> you retest this using 1.2.9?
> There are a number of permission restrictions that may 
> prevent log4net from finding the machine name, however that 
> is unlikely to be the case.
> 
> If you are using 1.2.9 and you want to expose your own 
> machine identifier you can set the value of a property 
> programmatically during your application startup. Something like this:
> 
> log4net.GlobalContext.Properties["host"] = 
> Environment.MachineName; /* Or your own value here */
> 
> Then you should be able to log the value to the database as follows:
> 
> <parameter>
>   <parameterName value="@machine_name" />
>   <dbType value="String" />
>   <size value="50" />
>   <layout type="log4net.Layout.PatternLayout" 
> value="%property{host}" /> </parameter>
> 
> Nicko
> 
> > -----Original Message-----
> > From: [EMAIL PROTECTED]
> > [mailto:[EMAIL PROTECTED]
> > Sent: 21 April 2005 10:19
> > To: [email protected]
> > Subject: RE: Machine name
> > 
> > This doesn't appear to work unfortunately.  In my .config 
> file I have:
> > 
> >             <param name="Parameter">
> >                 <param name="ParameterName" value="@machine_name" />
> >                 <param name="DbType" value="String" />
> >                 <param name="Size" value="50" />
> >                 <param name="Layout" 
> > type="log4net.Layout.PatternLayout">
> >                     <param name="ConversionPattern"
> > value="%P{log4net:HostName}" />
> >                 </param>
> >             </param>
> > 
> > (for some reason "%property{log4net:HostName}" was giving me 
> > WARNroperty{log4net:HostName} in the database as it didn't seem to 
> > work out the that the p was part of a word and treated is 
> as a "level" 
> > directive)
> > 
> > If I change the value to a string literal, it appears in 
> the database, 
> > so I assume it's something to do with the actual property.  
> I've also 
> > tried
> > putting:
> > 
> > <property name="Machine" value="MyServer" />
> > 
> > in the root of the <log4net> node and setting the 
> conversion pattern 
> > to "%P{Machine}" but this also writes an empty column to 
> the database.
> > 
> > Any pointers?
> > 
> > Cheers,
> > 
> > Bill
> > 
> > 
> >  -----Original Message-----
> > From:       Helbig, Dirk (EXTERN: HUD) 
> > [mailto:[EMAIL PROTECTED]
> > 
> > Sent:       21 April 2005 08:57
> > To: 'Log4NET User'
> > Cc: Bill Martin
> > Subject:    AW: Machine name
> > 
> > Hi,
> > 
> > we use this pattern in our environments:
> > 
> > %property{log4net:HostName}
> > 
> > I hope I could help you.
> > 
> > Dirk
> > 
> > -----Urspr�ngliche Nachricht-----
> > Von: [EMAIL PROTECTED]
> > [mailto:[EMAIL PROTECTED]
> > Gesendet: Donnerstag, 21. April 2005 09:44
> > An: [email protected]
> > Betreff: Machine name
> > 
> > 
> > I may be being dumb here, but I can't see any way of 
> getting hold of 
> > the machine name that an event is being logged from.
> > 
> > I have multiple machines in a cluster using an ADOAppender 
> to write to 
> > a common database, and I want to write a column with the 
> machine name 
> > in it.
> > Is there a simple way to get hold of the name?
> > 
> > Cheers,
> > 
> > Bill
> > 
> > 
> >  -----Original Message-----
> > From:       Nicko Cadell [mailto:[EMAIL PROTECTED] 
> > Sent:       18 April 2005 10:22
> > To: Log4NET User
> > Subject:    [Maybe Spam] RE: Problem with headers and 
> > footers in beta
> > 1.2.9
> > 
> > You need to use XML numeric character references:
> > 
> > \r = &#xD;
> > \n = &#xA;
> > 
> > Therefore \r\n becomes &#xD;&#xA; in XML.
> > 
> > Or alternatively you can use the PatternString type to 
> expand patterns 
> > in the header value, e.g.:
> > 
> > <header type="log4net.Util.PatternString" value="START 
> pid=%processid 
> > date=%date %newline" />
> > 
> > Cheers,
> > 
> > Nicko
> > 
> > > -----Original Message-----
> > > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> > > Sent: 18 April 2005 09:18
> > > To: [email protected]
> > > Subject: Problem with headers and footers in beta 1.2.9
> > > 
> > > Hello,
> > > 
> > > Last week, I downloaded the new 1.2.9 beta version and I 
> started to 
> > > convert one of my projects in order to use it.
> > > 
> > > But, now, as announced in the Breaking Changes list, C 
> style escape 
> > > sequences are not supported any more.
> > > 
> > > So far so good, but... With the previous versions, in the 
> Header and 
> > > Footer parameters, I added \\\"\\\\r\\\\n\\\" at the end 
> of the line 
> > > in order to avoid the first line of the log to be appended to the 
> > > header line.
> > > 
> > > Now that C style escape sequences are not translated, I 
> cannot find 
> > > how to force a new line at the end of the header line. (I 
> tried to 
> > > add %newline as it can be done in the ConversionPattern, 
> but, as I 
> > > could expect, it doesn't work because there is no pattern 
> > > interpretation in the Header and Footer parameters.
> > > 
> > > Therefore, is this a bug or is there another way to do it ?
> > > 
> > > By the way, congratulation for you excellent work. Log4net as 
> > > already saved me hours of work. It's so easy to integrate 
> it in a p! 
> > > roject !
> > > 
> > > Stephane Corteel
> > > Technical and R&D Director
> > > ASK sa
> > > www.ask.be
> > > 
> > > 
> > > 
> > 
> > 
> > 
> > 
> > UK businesses use 2 million tonnes of paper each year.
> > THINK before you PRINT this email.
> > ______________________________________________________________
> > 
> > CONFIDENTIALITY NOTICE
> > 
> > This communication and the information it contains is 
> intended for the 
> > person or organisation to whom it is addressed.  Its contents are 
> > confidential and may be protected in law.  Unauthorised 
> use,  copying 
> > or disclosure of any of it may be unlawful.
> > If you are not the intended recipient, please contact us 
> immediately.
> > 
> > The contents of any attachments in this e-mail may contain software 
> > viruses, which could damage your own computer system.  While 
> > Marlborough Stirling has taken every reasonable precaution 
> to minimise 
> > this risk, we cannot accept liability for any damage, which you 
> > sustain as a result of software viruses.  You should carry out your 
> > own virus checking procedure before opening any attachment.
> > 
> > Marlborough Stirling plc, Registered in England and Wales 
> Registered 
> > No. 3008820, Jessop House, Jessop Avenue, Cheltenham, 
> Gloucestershire, 
> > GL50 3SH
> > Tel: 01242 547000     Fax: 01242 547100
> > http://www.marlborough-stirling.com
> > 
> > 
> > 
> 
> 
> 

Reply via email to