OSDN Git Service

エラーログの出力先を変更
authorKimura Youichi <kim.upsilon@bucyou.net>
Thu, 9 May 2013 21:55:17 +0000 (06:55 +0900)
committerKimura Youichi <kim.upsilon@bucyou.net>
Thu, 9 May 2013 21:55:45 +0000 (06:55 +0900)
OpenTween.exe が配置されているディレクトリに新たに ErrorLogs ディレクトリが作成
され、その中にエラーログのファイルが生成されるようになります。

OpenTween.Tests/MyCommonTest.cs
OpenTween/MyCommon.cs
OpenTween/Resources/ChangeLog.txt

index e83aa27..6dc66e1 100644 (file)
@@ -30,6 +30,7 @@ using System.Runtime.InteropServices;
 using System.Reflection;
 using System.Windows.Forms;
 using System.Runtime.Serialization;
+using System.IO;
 
 namespace OpenTween
 {
@@ -207,5 +208,15 @@ namespace OpenTween
         {
             Assert.That(MyCommon.GetStatusUrl(screenName, statusId), Is.EqualTo(except));
         }
+
+        [Test]
+        public void GetErrorLogPathTest()
+        {
+            var mockAssembly = Substitute.For<_Assembly>();
+            mockAssembly.Location.Returns(@"C:\hogehoge\OpenTween\OpenTween.exe");
+            MyCommon.EntryAssembly = mockAssembly;
+
+            Assert.That(MyCommon.GetErrorLogPath(), Is.SamePath(@"C:\hogehoge\OpenTween\ErrorLogs\"));
+        }
     }
 }
index 1241b4a..fc7185a 100644 (file)
@@ -219,6 +219,11 @@ namespace OpenTween
                    Block | Unblock | UserUpdate | Deleted | ListCreated | ListUpdated | Unfollow),
         }
 
+        public static string GetErrorLogPath()
+        {
+            return Path.Combine(Path.GetDirectoryName(MyCommon.EntryAssembly.Location), "ErrorLogs");
+        }
+
         public static void TraceOut(Exception ex, string Message)
         {
             var buf = ExceptionOutMessage(ex);
@@ -235,8 +240,14 @@ namespace OpenTween
             lock (LockObj)
             {
                 if (!OutputFlag) return;
+
+                var logPath = MyCommon.GetErrorLogPath();
+                if (!Directory.Exists(logPath))
+                    Directory.CreateDirectory(logPath);
+
                 var now = DateTime.Now;
                 var fileName = string.Format("{0}Trace-{1:0000}{2:00}{3:00}-{4:00}{5:00}{6:00}.log", GetAssemblyName(), now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second);
+                fileName = Path.Combine(logPath, fileName);
 
                 using (var writer = new StreamWriter(fileName))
                 {
@@ -344,8 +355,14 @@ namespace OpenTween
             lock (LockObj)
             {
                 var IsTerminatePermission = true;
+
+                var logPath = MyCommon.GetErrorLogPath();
+                if (!Directory.Exists(logPath))
+                    Directory.CreateDirectory(logPath);
+
                 var now = DateTime.Now;
                 var fileName = string.Format("{0}-{1:0000}{2:00}{3:00}-{4:00}{5:00}{6:00}.log", GetAssemblyName(), now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second);
+                fileName = Path.Combine(logPath, fileName);
 
                 using (var writer = new StreamWriter(fileName))
                 {
index 04748f6..898d4f0 100644 (file)
@@ -4,6 +4,7 @@
  * NEW: タブの表示位置を画面上部に変更可能に (thx @aokomoriuta!)
  * NEW: mobile.twitter.com/<スクリーン名>/status/<ステータスID> のURLも関連発言表示の対象に追加
  * NEW: Favstarなどサードパーティ製サービスのパーマリンクURLも関連発言表示の対象に追加
+ * CHG: エラーログの出力先を変更 (OpenTween.exe と同じ場所に ErrorLogs フォルダが作成されます)
  * FIX: スペースが含まれているURLをブラウザで開こうとするとURLが分断されて複数のタブが開いてしまう問題を修正 (thx @5px!)
  * FIX: 画面更新時にInvalidOperationExceptionのエラーが発生する不具合を修正
  * FIX: 関連発言表示が非公開アカウントのツイートに対して機能しない問題を修正