2014-02-13 58 views
1

我有一個文件傳輸應用程序,需要將特定事件寫入特定的日誌文件,而所有事件都轉到了日誌文件。例如:專門的log4j日誌

File comes in from source A, events get written to file.log 
File comes in from source B, events get written to file.log and B_file.log 
File comes in from source C, events get written to file.log 
... 

我想在我的log4j的配置創建一個「博客」的appender,並在我的應用程序組中的所有我的源B文件/目錄到一個配置,併爲其分配「博客」,並在代碼檢查中,如果配置有appender,那麼每次我們傳輸文件時,如果有,請獲取並調用doAppend。

但是,如果我將appender添加到log4j配置中,是不是會讓它接收所有事件?我可以創建appender而不必將其分配給配置中的根目錄,但仍然可以通過編程方式獲取它?如果是這樣,這是否意味着每次我想發送一個事件到B_file.log,我必須得到appender,將它添加到root,調用doAppend,然後刪除appender?

有沒有更乾淨的方法來做到這一點?

在此先感謝!

回答