發表文章

目前顯示的是有「Logger」標籤的文章

「NLog」與「Sql Server」資料庫的完美搭配

圖片
一、前言 筆者工作時會將應用程式的資訊透過 NLog 寫入 Db(Sql Server) 。為了日後方便記憶,因此文章就這樣誕生了~ 二、開發環境 整合開發環境:Visual Studio 2019 語言:C# .net framework:4.6.2 三、 Nuget 安裝套件 NLog NLog.Config NLog.Schema 圖、套件清單 四、操作步驟 圖、修改 NLog.config 的 target 、 logger 元素 NLog.config 設定 < targets > < target name = "database" xsi:type = "Database" > < connectionStringName > DefaultConnection </ connectionStringName > <!--<connectionString>Data Source=(LocalDb)\MSSQLLocalDB;Initial Catalog=XXX;Integrated Security=True</connectionString>--> < commandText > INSERT INTO [dbo].[Log] ([MachineName] ,[Logged] ,[Level] ,[Message] ,[Logger] ,[Callsite] ,[Exception]) VALUES (@MachineName ,@Logged ,@Level ,@Message ...

使用「NLog」來記錄應用程式的大小事吧

圖片
一、介紹 NLog 是 .net 下的日誌套件,因為只要一句程式碼即可紀錄日誌,因此筆者常使用它記錄應用系統的錯誤、資訊…等。 二、開發環境 整合開發環境:Visual Studio 2019 語言:C# .net framework:4.6.2 三、 Nuget 安裝套件 NLog NLog.Config NLog.Schema 圖、套件清單 四、操作步驟 圖、修改 NLog.config 的 target 、 logger 元素 NLog.config 設定 < targets > < target xsi:type = "File" name = "f" fileName = "${basedir}/logs/${shortdate}.log" layout = "${longdate} ${uppercase:${level}} ${message}" /> </ targets > < rules > < logger name = "*" minlevel = "Debug" writeTo = "f" /> </ rules > 圖、使用 nlog 原始碼 c# public void LogTest() { var log = LogManager.GetCurrentClassLogger(); log.Info($"Test"); } 圖、執行後結果 五、相關連結 「NLog」與「Sql Server」資料庫的完美搭配 六、參考 NLog Tutorial NLog Nuget