Skip to content

Instantly share code, notes, and snippets.

@mk3008
Last active August 29, 2015 14:04
Show Gist options
  • Select an option

  • Save mk3008/e0891a206ef5d01aac19 to your computer and use it in GitHub Desktop.

Select an option

Save mk3008/e0891a206ef5d01aac19 to your computer and use it in GitHub Desktop.
アクションにロギング機能を差し込む(NLog)
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
<?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