INCREDIBLE - NTEventLogAppender.setSource DOESN'T work!!

P

ProgDario

HI,

I'm using the class NTEventLogAppender in log4j distribution.

My code is simple:

NTEventLogAppender eventLogAppender = new NTEventLogAppender();
eventLogAppender.setSource("ASDF"); // <-- I CHANGE THE SOURCE
eventLogAppender.setLayout(new PatternLayout("%m"));

But when I log into NT system, the source in the event viewer is
'log4j' instead of 'ASDF'.

If I use the constructor NTEventLogAppender("ASDF", layout), the source
becomes 'ASDF', but if I call the setSource method, the source DONESN'T
CHANGE!!

Any idea??

Thanks

:)ario
 
T

Tony Morris

ProgDario said:
HI,

I'm using the class NTEventLogAppender in log4j distribution.

My code is simple:

NTEventLogAppender eventLogAppender = new NTEventLogAppender();
eventLogAppender.setSource("ASDF"); // <-- I CHANGE THE SOURCE
eventLogAppender.setLayout(new PatternLayout("%m"));

But when I log into NT system, the source in the event viewer is
'log4j' instead of 'ASDF'.

If I use the constructor NTEventLogAppender("ASDF", layout), the source
becomes 'ASDF', but if I call the setSource method, the source DONESN'T
CHANGE!!

Any idea??

Thanks

:)ario

log4j is open source, why don't you figure it out?
My money is on user error.

--
Tony Morris
Software Engineer, IBM Australia.
BInfTech, SCJP 1.4, SCJD

http://www.jtiger.org/ JTiger Unit Test Framework for J2SE 1.5
http://qa.jtiger.org/ Java Q&A (FAQ, Trivia)
http://xdweb.net/~dibblego/
 
A

Alun Harford

ProgDario said:
HI,

I'm using the class NTEventLogAppender in log4j distribution.

My code is simple:

NTEventLogAppender eventLogAppender = new NTEventLogAppender();
eventLogAppender.setSource("ASDF"); // <-- I CHANGE THE SOURCE
eventLogAppender.setLayout(new PatternLayout("%m"));

But when I log into NT system, the source in the event viewer is
'log4j' instead of 'ASDF'.

If I use the constructor NTEventLogAppender("ASDF", layout), the source
becomes 'ASDF', but if I call the setSource method, the source DONESN'T
CHANGE!!

Groan.
Recompile your .class file with the new source.

Alun Harford
 
J

Joona I Palaste

ProgDario said:
I'm using the class NTEventLogAppender in log4j distribution.
My code is simple:
NTEventLogAppender eventLogAppender = new NTEventLogAppender();
eventLogAppender.setSource("ASDF"); // <-- I CHANGE THE SOURCE
eventLogAppender.setLayout(new PatternLayout("%m"));
But when I log into NT system, the source in the event viewer is
'log4j' instead of 'ASDF'.
If I use the constructor NTEventLogAppender("ASDF", layout), the source
becomes 'ASDF', but if I call the setSource method, the source DONESN'T
CHANGE!!
Any idea??

I had a look at the NTEventLogAppender source. Here is the constructor
NTEventLogAppender(String, String, Layout) which all other constructors
call:

public NTEventLogAppender(String server, String source, Layout layout)
{
if (source == null) {
source = "Log4j";
}
if (layout == null) {
this.layout = new TTCCLayout();
} else {
this.layout = layout;
}

try {
_handle = registerEventSource(server, source);
} catch (Exception e) {
e.printStackTrace();
_handle = 0;
}
}

Here is the method setSource(String):

public
void setSource(String source) {
this.source = source.trim();
}

Notice that it does NOT call registerEventSource(server, source),
whatever that does.

However, looking at the method activateOptions() we find:

public
void activateOptions() {
if (source != null) {
try {
_handle = registerEventSource(server, source);
} catch (Exception e) {
LogLog.error("Could not register event source.", e);
_handle = 0;
}
}
}

So maybe you'll have to call that after calling setSource(). Just a
guess, I don't have a Windows NT machine to test it on, and I don't
intend to get one.
 
P

ProgDario

THANKS Joona!!

You were right, I solved the problem!!

I also looked at the source but with no enough attention............


Thanks again


:)ario
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top