OSDN Git Service

Merge branch 'api11'
[opentween/open-tween.git] / OpenTween / MyCommon.cs
index 3e95522..3306feb 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))
                 {
@@ -391,7 +408,7 @@ namespace OpenTween
         /// マルチバイト文字のコードはUTF-8またはUnicodeで自動的に判断します。
         /// </newpara>
         /// </summary>
-        /// <param name = input>エンコード対象のURL</param>
+        /// <param name="_input">エンコード対象のURL</param>
         /// <returns>マルチバイト文字の部分をUTF-8/%xx形式でエンコードした文字列を返します。</returns>
 
         public static string urlEncodeMultibyteChar(string _input)
@@ -743,11 +760,9 @@ namespace OpenTween
         public static T CreateDataFromJson<T>(string content)
         {
             T data;
-            using (var stream = new MemoryStream())
+            var buf = Encoding.Unicode.GetBytes(content);
+            using (var stream = new MemoryStream(buf))
             {
-                var buf = Encoding.Unicode.GetBytes(content);
-                stream.Write(Encoding.Unicode.GetBytes(content), offset: 0, count: buf.Length);
-                stream.Seek(offset: 0, loc: SeekOrigin.Begin);
                 data = (T)((new DataContractJsonSerializer(typeof(T))).ReadObject(stream));
             }
             return data;