locked
logging ip address for incoming request using log4net RRS feed

  • Question

  • User1487175000 posted

    I am trying to log the ip address of incoming request. For logging i am using log4net 2.0.8.

    I used Application_BeginRequest method in global.asax to save the ip address of incoming request. However it seems like not working for multiple thread for same user.

    void Application_BeginRequest(object sender, EventArgs e) { 
    log4net.ThreadContext.Properties["addr"] = Request.UserHostAddress; }

    logs look like

    213.136.59.97 2018-11-30 07:35:33,561 [14] DEBUG Conference - Kitty:  visaBoka LoadPrintTimeline end: 
    (null) 2018-11-30 07:36:37,968 [32] DEBUG Conference - Kitty: Statistik  btnVisa_Click started
    Monday, December 3, 2018 9:51 AM

All replies

  • User-271186128 posted

    Hi shahid.majeed,

    However it seems like not working for multiple thread for same user.

    What do you mean not working? Log4Net itself is thread-safe, it works fine and handles multithreading scenarios well, you could check this thread.

    Best regards,
    Dillion

    Tuesday, December 4, 2018 3:16 AM
  • User1487175000 posted

    Hi Dillion

    What do you mean not working?

    Problem is null value for the second thread. seems like user is using multiple browser tab to work with my application. As you see in my logging output thread number change from 14 to 32.  So i wonder why it does not print the IP address for the second thread which is 32.

    Tuesday, December 4, 2018 9:21 AM