c# - log4net: Specifying different layouts for different kinds of messages in the same RollingFileAppender -


Apparently (or has been changed since?).

So how do I write a notification message with the layout and the exception with another layout, both for the same rolling tile? Is it possible to specify two different layouts in the same appender, or is there any other solution?

This is not really an issue of file (api), but lockingmodel is very much behind it .

As you have said, "Random" you can use Minimal Lock, though note that there are two main disadvantages:

  • Compared to exclusive lock Bad performance, because file lock has been acquired / released for every message.
  • This prevents only two processes from writing together. It may still be that more than one process attempts to write a file. In this case, only really one will be given, all other errors are received and their messages are lost (see also).

    To make it interruptible, you can write your own which uses a mute x internally, it is fast (A), file locking of minimized lock and (B) still allows all processes to finally write their messages (even though, as the intent of the course, mutually exclusive). I have an implementation that I can not share unfortunately because it is from a customer's project. But it should not be very difficult to come up with implementation (they can be one on the web, but I can not get it yet).

    Edit : An implementation in this, privately, I have not used it, so I can not tell that it works, but it looks fine.

    Update : Keeping in mind the "different layouts" part of the original question. I think it is not possible to have a single appender using two different layouts. You have two attenders, which are configured equally as layout, then they must be typed in the same file using custom locking modell or minim lock - YMMV. However, I really do not like this. Having two layouts (format!) In the same logfile parsing or log analysis becomes unnecessary, why not there are two files in the first place?

Comments