Can the outputs of multiple client request go to different log files?
Many developers are confronted with the problem of distinguishing the log output originating from the same class but different client requests. They come up with ingenious mechanisms to fan out the log output to different files. In most cases, this is not the right approach. It is simpler to use a context property or stack (ThreadContext). Typically, one would ThreadContext.Properties[“ID”] = “XXX” client specific information, such as the client’s hostname, ID or any other distinguishing information when starting to handle the client’s request. Thereafter, log output will automatically include the context data so that you can distinguish logs from different client requests even if they are output to the same file. See the ThreadContext and the PatternLayout classes for more information.
Many developers are confronted with the problem of distinguishing the log output originating from the same class but different client requests. They come up with ingenious mechanisms to fan out the log output to different files. In most cases, this is not the right approach. It is simpler to use a nested diagnostic context (NDC). Typically, one would NDC.Push() client specific information, such as the client’s hostname, ID or any other distinguishing information when starting to handle the client’s request. Thereafter, log output will automatically include the nested diagnostic context so that you can distinguish logs from different client requests even if they are output to the same file. See the NDC and the PatternLayout classes for more information.