Last active
August 29, 2015 14:04
-
-
Save mk3008/e0891a206ef5d01aac19 to your computer and use it in GitHub Desktop.
アクションにロギング機能を差し込む(NLog)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Imports System.Runtime.CompilerServices | |
| Public Module ActionExtension | |
| Private Logger As NLog.Logger = NLog.LogManager.GetCurrentClassLogger | |
| <Extension()> | |
| Public Sub InvokeWithLog(source As Action) | |
| Try | |
| Logger.Info("Start") | |
| source.Invoke() | |
| Logger.Info("Success") | |
| Catch ex As Exception | |
| Logger.Fatal("Fail", ex) | |
| Throw | |
| End Try | |
| End Sub | |
| End Module |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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"> | |
| <!-- | |
| See http://nlog-project.org/wiki/Configuration_file | |
| for information on customizing logging rules and outputs. | |
| intro: | |
| http://news.mynavi.jp/articles/2010/03/19/nlog/index.html | |
| examples: | |
| http://stackoverflow.com/questions/4091606/most-useful-nlog-configurations | |
| --> | |
| <!--詳細--> | |
| <variable name="verbose" value="${longdate} | ${processid:padding=5} | ${processname} | ${level:uppercase=true:padding=-5} | ${logger:padding=-30} | ${message}${onexception: ${newline}${exception:format=tostring}}" /> | |
| <variable name="line" value="----------------------------------------------------------------------------------------------------------------------------------------------------------------" /> | |
| <targets> | |
| <!--イミディエイトウインドウ--> | |
| <target name="debugger" xsi:type="Debugger" | |
| layout="${verbose}" | |
| header ="${line}" /> | |
| </targets> | |
| <rules> | |
| <!--*.ActionExtension用のログ設定--> | |
| <logger name="*.ActionExtension" maxlevel="Warn" writeTo="debugger" /> | |
| <logger name="*.ActionExtension" minlevel="Error" writeTo="debugger" /> | |
| </rules> | |
| </nlog> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment