Skip to content

Instantly share code, notes, and snippets.

@isdaviddong
Last active November 22, 2017 04:58

Revisions

  1. isdaviddong revised this gist Nov 22, 2017. No changes.
  2. isdaviddong created this gist Nov 20, 2017.
    23 changes: 23 additions & 0 deletions Logging.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    public class Logging : PolicyInjectionAttributeBase
    {
    //指定Log File Name
    public string LogFileName { get; set; }
    //override AfterInvoke方法
    public override void AfterInvoke()
    {
    var msg = $"\r\n Method '{this.MethodBase.Name}' has been called - {DateTime.Now.ToString()} ";
    SaveLog(msg);
    }
    //寫入Log
    private void SaveLog(string msg)
    {
    if (System.IO.File.Exists(LogFileName))
    {
    System.IO.File.AppendAllText(LogFileName, msg);
    }
    else
    {
    System.IO.File.WriteAllText(LogFileName, msg);
    }
    }
    }