0

I want to create a rolling log file per session (not a web server session) that is created on our server. I want to use the session name as part of the log file name.

Each session has an identifier which is partly made up from information sent from the connecting client, so there is no way to know what names new sessions will use until they're created. The number of sessions that will be created is not deterministic - it will likely be in the range of 1-50 over the period of a week.

I've seen a StackOverflow answer detailing an approach to programmatically create the log appenders, and I could make that do what I need, I think. But is it possible to do this using the standard log4net RollingFileAppender file config, and less/no code?

Community
  • 1
  • 1
Niall Connaughton
  • 15,518
  • 10
  • 52
  • 48
  • 1
    It's been years since I used log4net, but I vaguely remember doing something along these lines long, long ago. What I did was to read the log4net.config.xml file into an XML document object, manipulate the XML, and write it back to the disk again. If you are VERY interested in this method I might be able to find the details in some old files. – RenniePet Jun 19 '14 at 02:54
  • Thanks for your suggestion, I can see how that could work. I think if I go down the path of something quite manual, I may as well just create the appenders in code, so I can point them at whatever file I want to use. – Niall Connaughton Jun 19 '14 at 05:49
  • Gotta love the drive by down vote without comment – Niall Connaughton Jun 19 '14 at 05:50
  • Yeah. If I remember right, the advantage of modifying the XML file was that it allowed for some administrator interaction. The administrator could see what the system was doing, or trying to do, and could change trigger levels. I think. But I ended up dumping log4net and wrote my own little logging module. – RenniePet Jun 19 '14 at 11:03

1 Answers1

0

If you use ndc(Nested diagnostic context) like in my answer of your last question, there is no need to use global properties. The data is saved on the thread.

How to Log Client Ip, Browser Name and User Name using Log4net in asp.net? -> NDC logging

Community
  • 1
  • 1
Peter
  • 27,590
  • 8
  • 64
  • 84
  • Thanks for your suggestion. Can the NDC be used to dynamically determine the name of a file for an appender? I'm not trying to alter the content of the file, I'm trying to create a new file for different sessions. Btw, that last question you linked to was from user3729645, not me. – Niall Connaughton Jun 21 '14 at 07:32