Unity3D log写入文件
发布日期:2021-06-30 19:37:44
浏览次数:3
分类:技术文章
本文共 1157 字,大约阅读时间需要 3 分钟。
关键代码:Application.RegisterLogCallback(logCallBack);
using UnityEngine;using System.IO;public class Logger{ string fullPath; public void InitLogger() { fullPath = Application.dataPath + "/output.txt"; if (File.Exists(fullPath)) File.Delete(fullPath); Debug.Log(fullPath.Replace("/output.txt", "")); if (Directory.Exists(fullPath.Replace("/output.txt", ""))) { FileStream fs = File.Create(fullPath); fs.Close(); Application.logMessageReceived += logCallBack; } else { Debug.LogError("directory is not exist"); } } private void logCallBack(string condition, string stackTrace, LogType type) { if (File.Exists(fullPath)) { using (StreamWriter sw = File.AppendText(fullPath)) { sw.WriteLine(condition); sw.WriteLine(stackTrace); } } } private static Logger s_instance; public static Logger instance { get { if (null == s_instance) s_instance = new Logger(); return s_instance; } }}
转载地址:https://linxinfa.blog.csdn.net/article/details/46363335 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
初次前来,多多关照!
[***.217.46.12]2024年04月14日 03时56分17秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
UILabel自适应高度和自动换行
2019-04-30
NSTimer的使用方法 --初始化、暂停、继续
2019-04-30
iOS开发支付宝 集成SDK注意事项
2019-04-30
UIApplicationDelegate中几个常用的回调方法
2019-04-30
iOS开发遇到的问题
2019-04-30
Shell基本运算符
2019-04-30
Shell printf命令
2019-04-30
Shell流程控制
2019-04-30
Linux 命令大全
2019-04-30
Python的函数
2019-04-30
Python模块
2019-04-30
Shell脚本下载和编译ffmpeg
2019-04-30
ReactiveCocoa的使用
2019-04-30
FFmpeg的基础知识
2019-04-30
代理和block各自的优缺点和使用场景
2019-04-30
静态包中info.plist打进去之后,上线打包ipa报错
2019-04-30
dispatch_after使用方法详解
2019-04-30
iOS Xcode 8 快捷键 (注释 失效 处理)
2019-04-30
self与self class有什么用法上的区别
2019-04-30