- ${aspnet-application} - ASP.NET Application variable.
- ${aspnet-request} - ASP.NET Request variable.
- ${aspnet-session} - ASP.NET Session variable.
- ${aspnet-sessionid} - ASP.NET Session ID.
- ${aspnet-user-authtype} - ASP.NET User variable.
- ${aspnet-user-identity} - ASP.NET User variable.
透過Package Manager Console執行Install-Package NLog.Extended後,專案中會自動加入NLog.Extended.dll為參考。接下來我們也需要在NLog的設定檔中新增相對應的參考<extensions>元素至<nlog>元素下。
<?xml version="1.0" encoding="utf-8" ?> <nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <extensions> <add assembly="NLog.Extended" /> </extensions> <!--以下省略--> </nlog>設定完後將layout屬性設定為${aspnet-request:serverVariable=AUTH_USER}|${aspnet-request:serverVariable=HTTP_REFERER}|${longdate}|${level:uppercase:true},嘗試登入ASP.NET應用程式及瀏覽其它網頁,可以看到如下資訊被NLog記錄到
|http://localhost:60197/Account/Login|2013-04-02 17:26:26.3267|Debug
pete.chen|http://localhost:60197/Home/About|2013-04-02 17:33:00.8961|Debug
pete.chen是使用者的登入帳號。第一筆紀錄沒有帳號名稱的原因在於使用者尚未登入系統,登入系統後就可以成功擷取到帳號名稱了。
No comments:
Post a Comment