Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   INCREDIBLE - NTEventLogAppender.setSource DOESN'T work!! (http://www.velocityreviews.com/forums/t143227-incredible-nteventlogappender-setsource-doesnt-work.html)

ProgDario 05-04-2005 09:04 AM

INCREDIBLE - NTEventLogAppender.setSource DOESN'T work!!
 
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


Tony Morris 05-04-2005 11:29 AM

Re: INCREDIBLE - NTEventLogAppender.setSource DOESN'T work!!
 

"ProgDario" <dario@fga-software.com> wrote in message
news:1115197473.073994.65220@o13g2000cwo.googlegro ups.com...
> 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/



Alun Harford 05-04-2005 01:49 PM

Re: INCREDIBLE - NTEventLogAppender.setSource DOESN'T work!!
 

"ProgDario" <dario@fga-software.com> wrote in message
news:1115197473.073994.65220@o13g2000cwo.googlegro ups.com...
> 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



Joona I Palaste 05-04-2005 02:16 PM

Re: INCREDIBLE - NTEventLogAppender.setSource DOESN'T work!!
 
ProgDario <dario@fga-software.com> scribbled the following:
> 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??


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.

--
/-- Joona Palaste (palaste@cc.helsinki.fi) ------------- Finland --------\
\-------------------------------------------------------- rules! --------/
"Life without ostriches is like coffee with milk."
- Mika P. Nieminen

ProgDario 05-05-2005 06:31 AM

Re: INCREDIBLE - NTEventLogAppender.setSource DOESN'T work!!
 
THANKS Joona!!

You were right, I solved the problem!!

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


Thanks again


:)ario



All times are GMT. The time now is 08:15 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.