Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jiang Yin
committed
Dec 9, 2019
1 parent
178fc2e
commit deb578b
Showing
4 changed files
with
71 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using GameFramework; | ||
using System; | ||
using System.IO; | ||
using System.Text; | ||
using UnityEngine; | ||
using UnityGameFramework.Runtime; | ||
|
||
namespace Tutorial | ||
{ | ||
/// <summary> | ||
/// 带有文件打印的日志辅助器。 | ||
/// </summary> | ||
internal class FileLogHelper : DefaultLogHelper | ||
{ | ||
private readonly string CurrentLogPath = Utility.Path.GetRegularPath(Path.Combine(Application.persistentDataPath, "current.log")); | ||
private readonly string PreviousLogPath = Utility.Path.GetRegularPath(Path.Combine(Application.persistentDataPath, "previous.log")); | ||
|
||
public FileLogHelper() | ||
{ | ||
Application.logMessageReceived += OnLogMessageReceived; | ||
|
||
try | ||
{ | ||
if (File.Exists(PreviousLogPath)) | ||
{ | ||
File.Delete(PreviousLogPath); | ||
} | ||
|
||
if (File.Exists(CurrentLogPath)) | ||
{ | ||
File.Move(CurrentLogPath, PreviousLogPath); | ||
} | ||
} | ||
catch | ||
{ | ||
} | ||
} | ||
|
||
private void OnLogMessageReceived(string logMessage, string stackTrace, LogType logType) | ||
{ | ||
string log = Utility.Text.Format("[{0}][{1}] {2}{4}{3}{4}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), logType.ToString(), logMessage ?? "<Empty Message>", stackTrace ?? "<Empty StackTrace>", Environment.NewLine); | ||
try | ||
{ | ||
File.AppendAllText(CurrentLogPath, log, Encoding.UTF8); | ||
} | ||
catch | ||
{ | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters