tags:

views:

38

answers:

0

Hello,

I am writing a c# logger to be used in a busy, multi-threaded application.

I want to create 5 different loggers, where each of the loggers handles logging for different functionality.

The loggers will be called by static as well as nonstatic code.

Since the loggers write to a file, I want to synchronize the file access using lock(obj), where obj is an object specific to the logger instance.

Each logger can be obtained by name from a LoggerFactory. The LoggerFactory has a static reference to each of the loggers.

My question is: if one of these loggers is called to log a message from a static method, will the lock(obj) work? I have heard that in lock(obj), the obj should be static. If it is static, I think it's safe to call it from a static method.

The problem is: how can I create multiple instances of the logger if I lock on static object?