diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2017-06-21 10:57:08 -0400 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2017-06-21 10:57:08 -0400 |
| commit | 71adae0903ce2b9f837de58c3629eb4b62eda016 (patch) | |
| tree | 69913f8254a1de745372b622049c5f46abf083c6 | |
| parent | 694082ac01334d37be18ef05c3ec6684f9b7692b (diff) | |
add missing file
| -rw-r--r-- | Emby.Common.Implementations/Emby.Common.Implementations.csproj | 1 | ||||
| -rw-r--r-- | Emby.Common.Implementations/IO/SharpCifs/Util/DbsHelper/Log.cs | 118 |
2 files changed, 119 insertions, 0 deletions
diff --git a/Emby.Common.Implementations/Emby.Common.Implementations.csproj b/Emby.Common.Implementations/Emby.Common.Implementations.csproj index 00c90d16e..5b1defccb 100644 --- a/Emby.Common.Implementations/Emby.Common.Implementations.csproj +++ b/Emby.Common.Implementations/Emby.Common.Implementations.csproj @@ -228,6 +228,7 @@ <Compile Include="IO\SharpCifs\Smb\WinError.cs" /> <Compile Include="IO\SharpCifs\UniAddress.cs" /> <Compile Include="IO\SharpCifs\Util\Base64.cs" /> + <Compile Include="IO\SharpCifs\Util\DbsHelper\Log.cs" /> <Compile Include="IO\SharpCifs\Util\DES.cs" /> <Compile Include="IO\SharpCifs\Util\Encdec.cs" /> <Compile Include="IO\SharpCifs\Util\Hexdump.cs" /> diff --git a/Emby.Common.Implementations/IO/SharpCifs/Util/DbsHelper/Log.cs b/Emby.Common.Implementations/IO/SharpCifs/Util/DbsHelper/Log.cs new file mode 100644 index 000000000..eebf7c6b2 --- /dev/null +++ b/Emby.Common.Implementations/IO/SharpCifs/Util/DbsHelper/Log.cs @@ -0,0 +1,118 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + + +namespace SharpCifs.Util.DbsHelper +{ + public class Log + { + /// <summary> + /// コンソールへのログ出力を行うか否か + /// </summary> + public static bool IsActive { get; set; } = false; + + public static void Out(string message) + { + if (!Log.IsActive + || string.IsNullOrEmpty(message)) + return; + + var msg = DateTime.Now.ToString("HH:mm:ss.fff") + + ": [ThID: " + + System.Environment.CurrentManagedThreadId.ToString().PadLeft(3) + + " " + + message; + + Debug.WriteLine(msg); + Console.WriteLine(msg); + } + + /// <summary> + /// 例外のログ出力を行う。 + /// </summary> + /// <param name="ex"></param> + public static void Out(Exception ex) + { + if (!Log.IsActive + || ex == null) + return; + + Log.Out($"{ex}"); + var message = Log.GetHighlighted(Log.GetErrorString(ex)); + Log.Out(message); + } + + /// <summary> + /// Cast string-arrary to Highlighted message + /// 文字列配列を強調メッセージ形式文字列に変換する。 + /// </summary> + /// <param name="messages"></param> + /// <returns></returns> + private static string GetHighlighted(params System.String[] messages) + { + var time = DateTime.Now; + var list = new List<string>(); + + list.Add(""); + list.Add(""); + list.Add(time.ToString("HH:mm:ss.fff") + ":"); + list.Add("##################################################"); + list.Add("#"); + + foreach (string message in messages) + { + var lines = message.Replace("\r\n", "\n").Replace("\r", "\n").Trim('\n').Split('\n'); + foreach (var line in lines) + { + list.Add($"# {line}"); + } + } + + list.Add("#"); + list.Add("##################################################"); + list.Add(""); + list.Add(""); + + return string.Join("\r\n", list); + } + + /// <summary> + /// Get Formatted Exception-Info string-array + /// 例外情報を整形した文字列配列を返す。 + /// </summary> + /// <param name="ex"></param> + /// <returns></returns> + private static string[] GetErrorString(Exception ex) + { + var list = new List<string>(); + + if (ex.Message != null) + { + list.Add(ex.Message ?? ""); + list.Add(""); + } + + if (ex.StackTrace != null) + { + list.AddRange(ex.StackTrace.Split(new string[] { "場所", "at " }, + StringSplitOptions.None) + .AsEnumerable() + .Select(row => "\r\nat " + row)); + } + + if (ex.InnerException != null) + { + //InnerExceptionを再帰取得する。 + list.Add(""); + list.Add("Inner Exception"); + list.AddRange(Log.GetErrorString(ex.InnerException)); + } + + return list.ToArray(); + } + } +} |
