Event Log Weirdness.

2009-06-19 Thread James Green
Hi All,
 
I'm just looking into an odd issue.  I have an EventLogAppender being
configured in C#.  If I set this up to append to the Application log
all is fine.
 
However, when I ask it to create a custom event log called LogTest its
not working as expected.
 
Now the obvious thing is that the process doesn't have permissions ...
it does.  It created the new LogTest event log without problems but
never writes to it ...
 
From reading the log4net docs it would seem that if I can create the log
(which I can) it stands to reason that it should also be able to write
to it.
 
This isn't an ASPNET process either, its a desktop windows application
... the C# that configures the LogAppender is:
 
public static void ConfigureEventLogAppender(string appName, string
logName)
{
PatternLayout layout = GetDefaultLayout();
_eventLogAppender = new EventLogAppender();
_eventLogAppender.ApplicationName = appName;
_eventLogAppender.Layout = layout;
_eventLogAppender.LogName = logName;
_eventLogAppender.Threshold = Level.Off;
_eventLogAppender.ActivateOptions();
BasicConfigurator.Configure(_eventLogAppender);
}

I can only assume that I'm missing something in this setup process but I
can't see anything in the Xml versions of configuration that suggest
what to do ...

Cheers,

James Green
Technical Lead - Core Systems
Occam DM Ltd
Tel: +44(0)1761234716



RE: Event Log Weirdness.

2009-06-19 Thread James Green
I should also point out that I know the Threshold is Off ...

I have explicit methods that switch this on in order to prevent the
event log from being swamped with log entries as the processes we run
here could produce millions of logs a day ...

Our default log destination is a SQL Database ...

James. 

-Original Message-
From: James Green 
Sent: 19 June 2009 10:51
To: Log4NET User
Subject: Event Log Weirdness.

Hi All,
 
I'm just looking into an odd issue.  I have an EventLogAppender being
configured in C#.  If I set this up to append to the Application log
all is fine.
 
However, when I ask it to create a custom event log called LogTest its
not working as expected.
 
Now the obvious thing is that the process doesn't have permissions ...
it does.  It created the new LogTest event log without problems but
never writes to it ...
 
From reading the log4net docs it would seem that if I can create the log
(which I can) it stands to reason that it should also be able to write
to it.
 
This isn't an ASPNET process either, its a desktop windows application
... the C# that configures the LogAppender is:
 
public static void ConfigureEventLogAppender(string appName, string
logName)
{
PatternLayout layout = GetDefaultLayout();
_eventLogAppender = new EventLogAppender();
_eventLogAppender.ApplicationName = appName;
_eventLogAppender.Layout = layout;
_eventLogAppender.LogName = logName;
_eventLogAppender.Threshold = Level.Off;
_eventLogAppender.ActivateOptions();
BasicConfigurator.Configure(_eventLogAppender);
}

I can only assume that I'm missing something in this setup process but I
can't see anything in the Xml versions of configuration that suggest
what to do ...

Cheers,

James Green
Technical Lead - Core Systems
Occam DM Ltd
Tel: +44(0)1761234716


scanned by MessageLabs [www.messagelabs.com]

scanned by MessageLabs [www.messagelabs.com]




RE: Event Log Weirdness.

2009-06-19 Thread James Green
Do you call ActivateOptions() when Threshold property is changed?
Radovan

Indeed I do ...

public static void LogToEventLog(bool logToEventLog)
{
if (_eventLogAppender == null)
return;

if (logToEventLog)
{
_eventLogAppender.Threshold = Level.All;
}
else
{
_eventLogAppender.Threshold = Level.Off;
}
_eventLogAppender.ActivateOptions();
}

This is being shown in my console window:

log4net: EventLogAppender: Changing event source [MyFirstApp] from log
[Applicat
ion] to log [log4net]
log4net: EventLogAppender: Source [MyFirstApp] is registered to log
[log4net]






RE: Event Log Weirdness.

2009-06-19 Thread James Green
Hi Again,

I seem to have some info to work on.  Trying to log into my custom event
log has generated this in the Application event log:

The description for Event ID ( 0 ) in Source ( MyFirstApp ) cannot be
found. The local computer may not have the necessary registry
information or message DLL files to display messages from a remote
computer. You may be able to use the /AUXSOURCE= flag to retrieve this
description; see Help and Support for details. The following information
is part of the event: 2009-06-19 12:11:27,234 14 INFO MachineName
username Logging.TestHarness.vshost.exe (line: 220)
Logging.TestHarness.LogEntryCreator - Message number 71
System.Exception: Arses!

Hmm ... Any ideas would be great.

Cheers,

James.


EventLog Fun Continued.

2009-06-19 Thread James Green
Hi All,
 
I'm still at a total loss as to how to get log4net successfully writing
to a custom event log, writing to the Application event log is working
exactly as expected.
 
I have started using the IEventIDLog extension in order to pass over
event IDs to the log messages to see if this makes any difference.
 
I've looked over google a lot over the last couple of days and have
tried everything I have found in terms of suggestions.  The most recent
one being this:
 
http://www.mail-archive.com/log4net-user@logging.apache.org/msg02396.htm
l
 
Which talks of the same error I'm seeing in the application log that I
mentioned before:

I try to write to MyLog and this is entered into the Application log:

The description for Event ID ( 0 ) in Source ( MyFirstApp ) cannot be
found. The local computer may not have the necessary registry
information or message DLL files to display messages from a remote
computer. You may be able to use the /AUXSOURCE= flag to retrieve this
description; see Help and Support for details. The following information
is part of the event: 2009-06-19 12:11:27,234 14 INFO MachineName
username Logging.TestHarness.vshost.exe (line: 220)
Logging.TestHarness.LogEntryCreator - Message number 71
System.Exception

I think tried this suggestion:

ILog logger = LogManager.GetLogger(sender);
log4net.ThreadContext.Properties[EventID] = 12;
logger.Info(0,message);

Which didn't make any difference.  I have checked over the Sources key
entries being created in the registery and all seems to be correct in
there as well.  I just never see *anything* making it into the MyLog
event log.

I've probably got another 2 hours left to use on this before I have to
move onto other work which is incredibly frustrating as I will leave
behind a 'buggy' half finished wrapper.

Any input would be much appreciated.

:|

James


RE: Using AdoNetAppender

2009-06-17 Thread James Green
Hi Ron,
 
For sure, I totally understand that!
 
I think it would be good to include some C# config examples.  I just
have to finish off my wrapper and then I'll get my C# code over to you
for comment / inclusion in the docs.
 
Thanks!
 
James.

  _  

From: Ron Grabowski [mailto:rongrabow...@yahoo.com] 
Sent: 16 June 2009 23:00
To: Log4NET User
Subject: Re: Using AdoNetAppender


Its quite difficult to document every possible usage of a library. In
addition to these documents:

http://logging.apache.org/log4net/release/config-examples.html
http://logging.apache.org/log4net/release/sdk/log4net.Appender.AdoNetApp
ender.html
http://logging.apache.org/log4net/release/sdk/log4net.Appender.AdoNetApp
enderParameter.Layout.html

There's about 8,000 search results on Google for AdoNetAppender. 

A lot of the documentation is focused on XML examples because that's how
the majority of the users configure log4net.

I'll glady add your code configuration examples to AdoNetAppenderTest.cs
if attach them to a JIRA ticket!


  _  

From: James Green james.gr...@occam-dm.com
To: Log4NET User log4net-user@logging.apache.org
Sent: Tuesday, June 16, 2009 4:48:27 AM
Subject: RE: Using AdoNetAppender


Hi Again,
 
Surely, this is all pointing to a far bigger problem.  That is an
horrific piece of code!!  Surely this is doable in pure C#?
 
I'm amazed that this AdoNetAppender is so poorly documented and has so
few examples.  It's starting to put me off log4net!
 
James.

  _  

From: Ron Grabowski [mailto:rongrabow...@yahoo.com] 
Sent: 15 June 2009 22:32
To: Log4NET User
Subject: Re: Using AdoNetAppender


This page shows an example of loading an xml string into an XmlDocument
then configure log4net from the XmlDocument:

http://svn.apache.org/viewvc/logging/log4net/trunk/tests/src/Appender/Ad
oNetAppenderTest.cs?view=co

  _  

From: James Green james.gr...@occam-dm.com
To: Log4NET User log4net-user@logging.apache.org
Sent: Monday, June 15, 2009 12:04:16 PM
Subject: RE: Using AdoNetAppender


I think I'm going to have to try the config file method first.
 
I'm wrapping log4net and I don't want to cause every consuming component
to require loads of config information in it just for logging purposes.
 
Everything else is a sinch to configure in code, save for this appender
... *sigh* ...
 
Cheers,
 
James.

scanned by MessageLabs [www.messagelabs.com]


scanned by MessageLabs [www.messagelabs.com]



RE: Using AdoNetAppender

2009-06-16 Thread James Green
Hi Ron,
 
I did actually spot this just after posting the code and it did remove
the connection error I was seeing.
 
However, we have got it logging the date values now, however the other
fields are @log_level etc ... are still null.
 
Any ideas?
 
Cheers,
 
James.

  _  

From: Ron Grabowski [mailto:rongrabow...@yahoo.com] 
Sent: 15 June 2009 22:01
To: Log4NET User
Subject: Re: Using AdoNetAppender


If you don't specify a ConnectionType AdoNetAppender defaults to using
OleDbConnection which has a different connection string format than the
more common SqlConnection. Are you sure you want to use OleDbConnection?

Why not write a simple ConsoleApplication to test your code and look at
the configuration output log4net writes to Console.Out?

class Program
{
private static AdoNetAppender _sqlDatabaseAppender = new
AdoNetAppender();

static void Main(string[] args)
{
LogLog.InternalDebugging = true;
LogLog.EmitInternalMessages = true;

ConfigureDatabaseAppender(...);

ILog log = LogManager.GetLogger(typeof(Program));
log.Debug(Hello World);

Console.ReadLine();
}

public static void ConfigureDatabaseAppender(string connString)
{
// snip



  _  

From: James Green james.gr...@occam-dm.com
To: Log4NET User log4net-user@logging.apache.org
Sent: Monday, June 15, 2009 12:04:16 PM
Subject: RE: Using AdoNetAppender


I think I'm going to have to try the config file method first.
 
I'm wrapping log4net and I don't want to cause every consuming component
to require loads of config information in it just for logging purposes.
 
Everything else is a sinch to configure in code, save for this appender
... *sigh* ...
 
Cheers,
 
James.

scanned by MessageLabs [www.messagelabs.com]



RE: Using AdoNetAppender

2009-06-16 Thread James Green
Hi Again,
 
Surely, this is all pointing to a far bigger problem.  That is an
horrific piece of code!!  Surely this is doable in pure C#?
 
I'm amazed that this AdoNetAppender is so poorly documented and has so
few examples.  It's starting to put me off log4net!
 
James.

  _  

From: Ron Grabowski [mailto:rongrabow...@yahoo.com] 
Sent: 15 June 2009 22:32
To: Log4NET User
Subject: Re: Using AdoNetAppender


This page shows an example of loading an xml string into an XmlDocument
then configure log4net from the XmlDocument:

http://svn.apache.org/viewvc/logging/log4net/trunk/tests/src/Appender/Ad
oNetAppenderTest.cs?view=co

  _  

From: James Green james.gr...@occam-dm.com
To: Log4NET User log4net-user@logging.apache.org
Sent: Monday, June 15, 2009 12:04:16 PM
Subject: RE: Using AdoNetAppender


I think I'm going to have to try the config file method first.
 
I'm wrapping log4net and I don't want to cause every consuming component
to require loads of config information in it just for logging purposes.
 
Everything else is a sinch to configure in code, save for this appender
... *sigh* ...
 
Cheers,
 
James.

scanned by MessageLabs [www.messagelabs.com]



RE: Using AdoNetAppender

2009-06-16 Thread James Green
Cracked it ...

AdoNetAppenderParameter logLevel = new
AdoNetAppenderParameter();
logLevel.ParameterName = @log_level;
logLevel.Layout = new Layout2RawLayoutAdapter(new
PatternLayout(%level));
logLevel.Size = 50;
logLevel.DbType = System.Data.DbType.String;
_sqlDatabaseAppender.AddParameter(logLevel);

Regards,

James.


RE: Using AdoNetAppender

2009-06-16 Thread James Green
 bet that was a 'punching hands in the air' geek moment from hell

Indeed ... I may even make a cup of tea to celebrate! :)

Cheers,

James.


Using AdoNetAppender

2009-06-15 Thread James Green
Hi All,
 
I've spent about 4 hours today trying to get this working and have
totally failed so far.
 
I can't even really find much info on how to configure this purely in
Code.  In fact there is precious little I can find on the net in fact.
 
Here is the code I'm using the set up the AdoNetAppender in my app:
 
 
public static void ConfigureDatabaseAppender(string connString)
{
PatternLayout layout = GetDefaultLayout();
_sqlDatabaseAppender = new AdoNetAppender();
_sqlDatabaseAppender.Layout = layout;
_sqlDatabaseAppender.UseTransactions = false;
_sqlDatabaseAppender.BufferSize = 1;
 
_sqlDatabaseAppender.CommandType = System.Data.CommandType.Text;
_sqlDatabaseAppender.ConnectionString = connString;
_sqlDatabaseAppender.CommandText = INSERT INTO Log
([Date],[Level],[Thread],[Logger],[Message],[Exception]) VALUES
(@log_date, @log_level, @thread, @logger, @message, @exception);
AdoNetAppenderParameter logDate = new AdoNetAppenderParameter();
RawTimeStampLayout dateLayout = new RawTimeStampLayout();
logDate.ParameterName = @log_date;
logDate.Layout = dateLayout;
logDate.DbType = System.Data.DbType.DateTime;
_sqlDatabaseAppender.AddParameter(logDate);
AdoNetAppenderParameter logThread = new AdoNetAppenderParameter();
logThread.ParameterName = @thread;
logThread.Size = 255;
logThread.DbType = System.Data.DbType.String;
_sqlDatabaseAppender.AddParameter(logThread);
AdoNetAppenderParameter logLevel = new AdoNetAppenderParameter();
logLevel.ParameterName = @log_level;
logLevel.Size = 50;
logLevel.DbType = System.Data.DbType.String;
_sqlDatabaseAppender.AddParameter(logLevel);
AdoNetAppenderParameter logLogger = new AdoNetAppenderParameter();
logLogger.ParameterName = @logger;
logLogger.Size = 255;
logLogger.DbType = System.Data.DbType.String;
_sqlDatabaseAppender.AddParameter(logLogger);
AdoNetAppenderParameter logMessage = new AdoNetAppenderParameter();
logMessage.ParameterName = @message;
logMessage.Size = 4000;
logMessage.DbType = System.Data.DbType.String;
_sqlDatabaseAppender.AddParameter(logMessage);
AdoNetAppenderParameter logException = new AdoNetAppenderParameter();
logException.ParameterName = @exception;
logException.Size = 2000;
logException.DbType = System.Data.DbType.String;
_sqlDatabaseAppender.AddParameter(logException);
_sqlDatabaseAppender.ActivateOptions();
 
BasicConfigurator.Configure(_sqlDatabaseAppender);
}

Any help would be great.

James.



RE: Using AdoNetAppender

2009-06-15 Thread James Green
I may have to try that.  Currently it just fails with an Oject
reference not set to an instance of an object.

Thanks,

James. 

-Original Message-
From: Matt Lund [mailto:ml...@control4.com] 
Sent: 15 June 2009 16:28
To: Log4NET User
Subject: RE: Using AdoNetAppender

Have you already gotten AdoNetAppender to work from a app.config /
web.config first?  If not, I'd suggest getting that to work first.  You
may learn something in that process and it'll spark a realization of
what you're missing in the from-code approach?

-Original Message-
From: James Green [mailto:james.gr...@occam-dm.com] 
Sent: Monday, June 15, 2009 9:26 AM
To: Log4NET User
Subject: Using AdoNetAppender

Hi All,
 
I've spent about 4 hours today trying to get this working and have
totally failed so far.
 
I can't even really find much info on how to configure this purely in
Code.  In fact there is precious little I can find on the net in fact.
 
Here is the code I'm using the set up the AdoNetAppender in my app:
 
 
public static void ConfigureDatabaseAppender(string connString)
{
PatternLayout layout = GetDefaultLayout();
_sqlDatabaseAppender = new AdoNetAppender();
_sqlDatabaseAppender.Layout = layout;
_sqlDatabaseAppender.UseTransactions = false;
_sqlDatabaseAppender.BufferSize = 1;
 
_sqlDatabaseAppender.CommandType = System.Data.CommandType.Text;
_sqlDatabaseAppender.ConnectionString = connString;
_sqlDatabaseAppender.CommandText = INSERT INTO Log
([Date],[Level],[Thread],[Logger],[Message],[Exception]) VALUES
(@log_date, @log_level, @thread, @logger, @message, @exception);
AdoNetAppenderParameter logDate = new AdoNetAppenderParameter();
RawTimeStampLayout dateLayout = new RawTimeStampLayout();
logDate.ParameterName = @log_date;
logDate.Layout = dateLayout;
logDate.DbType = System.Data.DbType.DateTime;
_sqlDatabaseAppender.AddParameter(logDate);
AdoNetAppenderParameter logThread = new AdoNetAppenderParameter();
logThread.ParameterName = @thread;
logThread.Size = 255;
logThread.DbType = System.Data.DbType.String;
_sqlDatabaseAppender.AddParameter(logThread);
AdoNetAppenderParameter logLevel = new AdoNetAppenderParameter();
logLevel.ParameterName = @log_level;
logLevel.Size = 50;
logLevel.DbType = System.Data.DbType.String;
_sqlDatabaseAppender.AddParameter(logLevel);
AdoNetAppenderParameter logLogger = new AdoNetAppenderParameter();
logLogger.ParameterName = @logger;
logLogger.Size = 255;
logLogger.DbType = System.Data.DbType.String;
_sqlDatabaseAppender.AddParameter(logLogger);
AdoNetAppenderParameter logMessage = new AdoNetAppenderParameter();
logMessage.ParameterName = @message;
logMessage.Size = 4000;
logMessage.DbType = System.Data.DbType.String;
_sqlDatabaseAppender.AddParameter(logMessage);
AdoNetAppenderParameter logException = new AdoNetAppenderParameter();
logException.ParameterName = @exception;
logException.Size = 2000;
logException.DbType = System.Data.DbType.String;
_sqlDatabaseAppender.AddParameter(logException);
_sqlDatabaseAppender.ActivateOptions();
 
BasicConfigurator.Configure(_sqlDatabaseAppender);
}

Any help would be great.

James.


scanned by MessageLabs [www.messagelabs.com]




RE: Using AdoNetAppender

2009-06-15 Thread James Green
I think I'm going to have to try the config file method first.
 
I'm wrapping log4net and I don't want to cause every consuming component
to require loads of config information in it just for logging purposes.
 
Everything else is a sinch to configure in code, save for this appender
... *sigh* ...
 
Cheers,
 
James.

  _  

From: codingvi...@googlemail.com [mailto:codingvi...@googlemail.com] On
Behalf Of Wayne Douglas
Sent: 15 June 2009 16:57
To: Log4NET User
Subject: Re: Using AdoNetAppender


AppConfig is much simpler - you should start with that then convert to
this if you need to - not sure why you'd need to tho?


On Mon, Jun 15, 2009 at 4:31 PM, James Green james.gr...@occam-dm.com
wrote:


I may have to try that.  Currently it just fails with an Oject
reference not set to an instance of an object.

Thanks,

James.


-Original Message-
From: Matt Lund [mailto:ml...@control4.com]
Sent: 15 June 2009 16:28
To: Log4NET User
Subject: RE: Using AdoNetAppender

Have you already gotten AdoNetAppender to work from a app.config
/
web.config first?  If not, I'd suggest getting that to work
first.  You
may learn something in that process and it'll spark a
realization of
what you're missing in the from-code approach?

-Original Message-
From: James Green [mailto:james.gr...@occam-dm.com]
Sent: Monday, June 15, 2009 9:26 AM
To: Log4NET User
Subject: Using AdoNetAppender

Hi All,

I've spent about 4 hours today trying to get this working and
have
totally failed so far.

I can't even really find much info on how to configure this
purely in
Code.  In fact there is precious little I can find on the net in
fact.

Here is the code I'm using the set up the AdoNetAppender in my
app:


public static void ConfigureDatabaseAppender(string connString)
{
PatternLayout layout = GetDefaultLayout();
_sqlDatabaseAppender = new AdoNetAppender();
_sqlDatabaseAppender.Layout = layout;
_sqlDatabaseAppender.UseTransactions = false;
_sqlDatabaseAppender.BufferSize = 1;

_sqlDatabaseAppender.CommandType = System.Data.CommandType.Text;
_sqlDatabaseAppender.ConnectionString = connString;
_sqlDatabaseAppender.CommandText = INSERT INTO Log
([Date],[Level],[Thread],[Logger],[Message],[Exception]) VALUES
(@log_date, @log_level, @thread, @logger, @message,
@exception);
AdoNetAppenderParameter logDate = new AdoNetAppenderParameter();
RawTimeStampLayout dateLayout = new RawTimeStampLayout();
logDate.ParameterName = @log_date;
logDate.Layout = dateLayout;
logDate.DbType = System.Data.DbType.DateTime;
_sqlDatabaseAppender.AddParameter(logDate);
AdoNetAppenderParameter logThread = new
AdoNetAppenderParameter();
logThread.ParameterName = @thread;
logThread.Size = 255;
logThread.DbType = System.Data.DbType.String;
_sqlDatabaseAppender.AddParameter(logThread);
AdoNetAppenderParameter logLevel = new
AdoNetAppenderParameter();
logLevel.ParameterName = @log_level;
logLevel.Size = 50;
logLevel.DbType = System.Data.DbType.String;
_sqlDatabaseAppender.AddParameter(logLevel);
AdoNetAppenderParameter logLogger = new
AdoNetAppenderParameter();
logLogger.ParameterName = @logger;
logLogger.Size = 255;
logLogger.DbType = System.Data.DbType.String;
_sqlDatabaseAppender.AddParameter(logLogger);
AdoNetAppenderParameter logMessage = new
AdoNetAppenderParameter();
logMessage.ParameterName = @message;
logMessage.Size = 4000;
logMessage.DbType = System.Data.DbType.String;
_sqlDatabaseAppender.AddParameter(logMessage);
AdoNetAppenderParameter logException = new
AdoNetAppenderParameter();
logException.ParameterName = @exception;
logException.Size = 2000;
logException.DbType = System.Data.DbType.String;
_sqlDatabaseAppender.AddParameter(logException);
_sqlDatabaseAppender.ActivateOptions();

BasicConfigurator.Configure(_sqlDatabaseAppender);
}

Any help would be great.

James.



scanned by MessageLabs [www.messagelabs.com]







-- 
Cheers,

w://

scanned by MessageLabs [www.messagelabs.com]