INCREDIBLE - NTEventLogAppender.setSource DOESN'T work!!

Discussion in 'Java' started by ProgDario, May 4, 2005.

  1. ProgDario

    ProgDario Guest

    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
     
    ProgDario, May 4, 2005
    #1
    1. Advertising

  2. ProgDario

    Tony Morris Guest

    "ProgDario" <> wrote in message
    news:...
    > 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/
     
    Tony Morris, May 4, 2005
    #2
    1. Advertising

  3. ProgDario

    Alun Harford Guest

    "ProgDario" <> wrote in message
    news:...
    > 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
     
    Alun Harford, May 4, 2005
    #3
  4. ProgDario <> 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 () ------------- Finland --------\
    \-------------------------------------------------------- rules! --------/
    "Life without ostriches is like coffee with milk."
    - Mika P. Nieminen
     
    Joona I Palaste, May 4, 2005
    #4
  5. ProgDario

    ProgDario Guest

    THANKS Joona!!

    You were right, I solved the problem!!

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


    Thanks again


    :)ario
     
    ProgDario, May 5, 2005
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    480
  2. skye.shaw
    Replies:
    0
    Views:
    419
    skye.shaw
    Aug 11, 2005
  3. Replies:
    0
    Views:
    376
  4. Replies:
    0
    Views:
    394
  5. Arondelle

    Just see this...It`s incredible!

    Arondelle, Jul 6, 2004, in forum: HTML
    Replies:
    2
    Views:
    455
    Will Gittoes
    Jul 7, 2004
Loading...

Share This Page