3 * Copyright(c) 2022 Samsung Electronics Co., Ltd.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
20 using global::System.IO;
21 using global::System.Diagnostics;
25 internal class DebugFileLogging : Disposable
27 #region Constant Fields
28 private string logFolderPath;
29 #endregion //Constant Fields
32 public static DebugFileLogging Instance => instance;
33 private static readonly DebugFileLogging instance = new DebugFileLogging();
34 private string filePath;
35 private FileStream file;
39 private DebugFileLogging()
41 if (Environment.OSVersion.Platform == PlatformID.Unix || Environment.OSVersion.Platform == PlatformID.MacOSX)
43 logFolderPath = Environment.GetEnvironmentVariable("HOME") + "/nui/";
47 logFolderPath = Environment.ExpandEnvironmentVariables("%HOMEDRIVE%%HOMEPATH%") + "/owner/share/nui/";
50 Directory.CreateDirectory(logFolderPath);
52 var id = Process.GetCurrentProcess().Id;
53 filePath = logFolderPath + id.ToString();
54 file = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.ReadWrite);
56 #endregion //Constructors
59 [Conditional("NUI_DEBUG_ON")]
60 internal void WriteLog(string log)
62 TimeSpan curr = DateTime.Now.TimeOfDay;
64 FileStream file = new FileStream(filePath, FileMode.Append, FileAccess.Write);
65 StreamWriter write = new StreamWriter(file);
66 var time = String.Format("[{0,-13}] ", curr.TotalMilliseconds);
67 write.WriteLine(time + log);