2010-12-05 97 views
1

尋找替代現有(幾乎遺留)應用程序中的日誌記錄。這將基於eventId記錄事件並將dll配置爲事件消息文件(日誌記錄已完成到事件日誌和消息隊列)。整個日誌記錄取決於事件ID,因爲一些記錄的事件會根據事件ID上傳到企業所在的國際化中。 對於此日誌記錄基礎結構,還添加了一些文件日誌記錄,它不使用此事件消息文件,而是記錄純文本字符串(內置文件翻轉和歸檔支持)。.net使用eventid支持登錄

我正在尋找一個日誌記錄框架,它將具有基於id(Error(id,object [] args))和「普通」消息(錯誤(字符串消息,對象[] args))的日誌記錄標準接口。

log4net和nlog都沒有這樣的接口。

有沒有支持這個架子的日誌框架還是我必須自己構建。或者以某種方式爲此調整log4net/nlog。

感謝, 林

回答

1

看到這個link的log4net的「延伸」,使您可以合理地輕鬆添加事件ID記錄消息。

下面是來自log4net的鏈接的簡要摘錄:

public interface IEventIDLog : ILog 
{ 
    void Info(int eventId, object message); 
    void Info(int eventId, object message, Exception t); 
} 

public class EventIDLogImpl : LogImpl, IEventIDLog 
{ 
    /// <summary> 
    /// The fully qualified name of this declaring type not the type of any subclass. 
    /// </summary> 

    private readonly static Type ThisDeclaringType = typeof(EventIDLogImpl); 

    public EventIDLogImpl(ILogger logger) : base(logger) 
    { 
    } 


    #region Implementation of IEventIDLog 
    public void Info(int eventId, object message) 
    { 
    Info(eventId, message, null); 
    } 


    public void Info(int eventId, object message, System.Exception t) 
    { 
    if (this.IsInfoEnabled) 
    { 
     LoggingEvent loggingEvent = new LoggingEvent(ThisDeclaringType, Logger.Repository, Logger.Name, Level.Info, message, t); 
     loggingEvent.Properties["EventID"] = eventId; 
     Logger.Log(loggingEvent); 
    } 
    } 
} 

我看不出有任何理由,你爲什麼不能做NLog類似的東西。這是NLog的github源代碼庫中的link to some examples of extending the NLog Logger

我還會注意到System.Diagnostics.TraceSource也支持記錄EventId。如果考慮System.Diagnostics,則可能還需要考慮使用Ukadc.Diagnostics以獲得類似於可以使用log4net和NLog所做的強大格式化功能。

1

您還可以將遺留應用程序的記錄集成到正常的日誌記錄基礎結構中。這可以通過使用.net Common.Loggingrouting feature輕鬆實現,它是日誌框架的抽象(它支持enteprise lib,log4net,NLog,System.Trace)。

0

TraceSource.TraceEvent-Methode提供了爲日誌事件傳遞數字標識符的可能性,以及可用於記錄「普通」消息的方法。

+0

有關TraceEvent-Method的id的一些附加信息可用[here](http://stackoverflow.com/questions/17590453/what-should-i-identify-with-the-id-argument-in- tracesource-traceevent法) – Sonic78 2016-10-25 11:55:54