一般我们在做项目的反馈日志收集的时候都会根据提交的后台日志判断线后Bug产生的大概原因,直接帮我们缩小范围。

#region 模块信息
// **********************************************************************
// Copyright (C) 2019 jiamiantech
// Please contact me if you have any questions
// File Name:             WriteLog
// Author:                幻世界
// WeChat||QQ:            at853394528 || 853394528
// **********************************************************************
#endregion
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text;
using UnityEngine;
using Debug = UnityEngine.Debug;public class WriteLog : MonoBehaviour
{private static FileStream FileWriter;private static UTF8Encoding encoding;private static WriteLog consoleLog;public static WriteLog ConsoleLog //开启单例{get{if (consoleLog == null)consoleLog = new WriteLog();return consoleLog;}}public void LogStart(){Debug.LogError("开始写入日志");Directory.CreateDirectory(Application.persistentDataPath + "/Log");string NowTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace(" ", "_").Replace("/", "_").Replace(":", "_");FileInfo fileInfo = new FileInfo(Application.persistentDataPath + "/Log/" + NowTime + "_Log.txt");//设置Log文件输出地址FileWriter = fileInfo.Open(FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Read);encoding = new UTF8Encoding();Application.logMessageReceived += LogCallback;}/// <summary>/// Log回调/// </summary>/// <param name="condition">输出内容</param>/// <param name="stackTrace">堆栈追踪</param>/// <param name="type">Log日志类型</param>private void LogCallback(string condition, string stackTrace, LogType type) //写入控制台数据{//输出的日志类型可以自定义string content = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + "【" + type + "】" + "【" + stackTrace + "】" + ":" + condition + Environment.NewLine+ Environment.NewLine;FileWriter.Write(encoding.GetBytes(content), 0, encoding.GetByteCount(content));FileWriter.Flush();}private void OnDestroy() //关闭写入{if ((FileWriter != null)){Debug.LogError("日志写入结束");FileWriter.Close();Application.logMessageReceived-= LogCallback;}}private static void PhoneSystemInfo(StreamWriter sw){sw.WriteLine("*********************************************************************************************************start");sw.WriteLine("By " + SystemInfo.deviceName);DateTime now = DateTime.Now;sw.WriteLine(string.Concat(new object[] { now.Year.ToString(), "年", now.Month.ToString(), "月", now.Day, "日  ", now.Hour.ToString(), ":", now.Minute.ToString(), ":", now.Second.ToString() }));sw.WriteLine();sw.WriteLine("操作系统:  " + SystemInfo.operatingSystem);sw.WriteLine("系统内存大小:  " + SystemInfo.systemMemorySize);sw.WriteLine("设备模型:  " + SystemInfo.deviceModel);sw.WriteLine("设备唯一标识符:  " + SystemInfo.deviceUniqueIdentifier);sw.WriteLine("处理器数量:  " + SystemInfo.processorCount);sw.WriteLine("处理器类型:  " + SystemInfo.processorType);sw.WriteLine("显卡标识符:  " + SystemInfo.graphicsDeviceID);sw.WriteLine("显卡名称:  " + SystemInfo.graphicsDeviceName);sw.WriteLine("显卡标识符:  " + SystemInfo.graphicsDeviceVendorID);sw.WriteLine("显卡厂商:  " + SystemInfo.graphicsDeviceVendor);sw.WriteLine("显卡版本:  " + SystemInfo.graphicsDeviceVersion);sw.WriteLine("显存大小:  " + SystemInfo.graphicsMemorySize);sw.WriteLine("显卡着色器级别:  " + SystemInfo.graphicsShaderLevel);sw.WriteLine("是否图像效果:  " + SystemInfo.supportsImageEffects);sw.WriteLine("是否支持内置阴影:  " + SystemInfo.supportsShadows);sw.WriteLine("*********************************************************************************************************end");sw.WriteLine("LogInfo:");sw.WriteLine();}}
2019-08-26 14:21:06 【Log】【UnityEngine.Debug:Log(Object)
Main:DebugPlatformMesaage() (at Assets/Scripts/Main.cs:470)
Main:Start() (at Assets/Scripts/Main.cs:25)
】:Current Platform:UNITY_EDITOR2019-08-26 14:21:06 【Log】【UnityEngine.Debug:Log(Object)
Main:InitManager() (at Assets/Scripts/Main.cs:54)
Main:Start() (at Assets/Scripts/Main.cs:26)
】:当前设备分辨率:1920 X 12002019-08-26 14:21:06 【Log】【UnityEngine.Debug:Log(Object)
GameManager:SetUp() (at Assets/Scripts/Game/Managers/GameManager.cs:50)
Main:InitManager() (at Assets/Scripts/Main.cs:56)
Main:Start() (at Assets/Scripts/Main.cs:26)
】:本地IP :192.168.191.12019-08-26 14:21:06 【Log】【UnityEngine.Debug:Log(Object)
GameManager:SetUp() (at Assets/Scripts/Game/Managers/GameManager.cs:53)
Main:InitManager() (at Assets/Scripts/Main.cs:56)
Main:Start() (at Assets/Scripts/Main.cs:26)
】:当前设备唯一ID :a96398d803bbe28559a0992d92b54a418e4902712019-08-26 14:21:06 【Log】【UnityEngine.Debug:Log(Object)
GameManager:PingNetAddress() (at Assets/Scripts/Game/Managers/GameManager.cs:189)
GameManager:SetUp() (at Assets/Scripts/Game/Managers/GameManager.cs:59)
Main:InitManager() (at Assets/Scripts/Main.cs:56)
Main:Start() (at Assets/Scripts/Main.cs:26)
】:True  2019-08-26 14:21:06 【Log】【UnityEngine.Debug:Log(Object)
Main:CheckExtractResource() (at Assets/Scripts/Main.cs:218)
Main:Start() (at Assets/Scripts/Main.cs:28)
】:资源已经释放到本地2019-08-26 14:21:06 【Log】【UnityEngine.Debug:Log(Object)
Main:CheckExtractResource() (at Assets/Scripts/Main.cs:223)
Main:Start() (at Assets/Scripts/Main.cs:28)
】:当前资源版本 :1.0.0

【Unity开发小技巧】Unity日志输出存储相关推荐

  1. 【Unity开发小技巧】Unity打包IOS端APP

    目录 一:安装IOS的模块并打包 1.Hub可以添加IOS模块 2.项目内部下载安装ISO模块 3.添加我们需要打包的场景 二:XCode工程内部设置并打包 1.mac商店安装XCode软件并打开xc ...

  2. 【Unity开发小技巧】FMS有限状态机详解

    欢迎加入Unity业内qq交流群:956187480 qq扫描二维码加群 在实际开发中很多时候对某类别的对象都需要有多种状态的管理和切换,这个时候我们就可以引入FMS状态机概念,有限状态机主要有三要素 ...

  3. 【Unity开发小技巧】模型单指旋转双指缩放功能代码(多种情况)

    欢迎加入Unity业内qq交流群:956187480 qq扫描二维码加群 1.pc端通过鼠标中键调整相机的FieldOfView属性的值(会发生形变不建议) void Update(){if (Inp ...

  4. 【Unity开发小技巧】AudioManager声音管理器

    欢迎加入Unity业内qq交流群:956187480 qq扫描二维码加群,行业纵横颇多,每个人精通领域各异,旨在交流, 在项目里做音频管理的时候,我们往往是跟资源管理结合起来的,但是这里我们就单音频管 ...

  5. 【Unity开发小技巧】iOS APP下载安装时,如果出现此时无法下载安装APP的字样时,一些解决思路

    目录 一.OS系统和IOS版本更新 ​二:App-Store方式 三:Ad-hoc方式 四:In-house 方式 五: Architecture设置错误 六:App 支持的 iOS 系统版本,和当前 ...

  6. 【Unity开发小技巧】Unity随机概率扩展(概率可调控)

    做了以下两张图有助于理解,如果想调控概率的话直接修改概率数组即可,实战案例:http://t.csdn.cn/P9QKJ 其实在做概率类相关的界面效果的时候,我们真实做法都是在刷新界面前已经把结果获取 ...

  7. 后端 CUID 开发小技巧

    后端 CUID 开发小技巧 1.不在用HashMap存储条件 只需要一行代码 将传输对象存储转换成Map 进行查询 Map<String, Object> conditions = JSO ...

  8. 移动Web开发小技巧

    移动Web开发小技巧 添加到主屏后的标题(IOS) name="apple-mobile-web-app-title" content="标题"> 启用  ...

  9. 《旭日X3派开发小技巧》—— 备份与恢复SD卡镜像

    0.前言 很多小伙伴们在开发旭日X3派后,想备份自己魔改后的镜像,官方手册中提供了根文件系统制作的方法,但此种方法对于想备份自己开发魔改过后的镜像非常不方便,在这里给大家提供一个较为简便的方法,可以方 ...

最新文章

  1. 为什么Android教程中的大多数字段(类成员)都以`m`开头?
  2. MyBatis MapperScannerConfigurer配置——MyBatis学习笔记之八
  3. 关于 PHP 与 MYSQL的链接
  4. DCMTK:使用dcmimage 库将DICOM图像转换为PPM或PGM
  5. HDFS的Secondarynamenode工作机制
  6. 领域应用 | OMAHA联盟发布“疾病临床表现”、“中毒”知识图谱及OMAHA知识库
  7. android 上线流程
  8. UINavigationBar的创建
  9. 如何正确地使用arXiv平台
  10. 系统安装之十 U盘安装原版win10
  11. ffmpeg截取jpg图_使用ffmpeg进行视频封面截取
  12. 冒险岛079单机/小范围联机游戏搭建
  13. I Irrational Division
  14. oppo小布机器人_OPPO小布助手建立GUI+VUI协作机制,创新快应用融合能力
  15. 简述html的文档基本结构,【简答题】简述 HTML 文档的基本结构。
  16. 关于CFree5.0中设置支持C99模式
  17. 9 9简单的数独游戏python_如何使用tkinter GUI python创建9*9数独生成器?
  18. 隔壁住着一个过气的明星是什么体验?
  19. 数据库服务器压缩文件,服务器数据库怎么压缩文件
  20. 二手苹果手机价格表最新

热门文章

  1. php实现验证码(数字、字母、汉字)
  2. opencv---c++
  3. 利用机器学习预测外汇汇率
  4. 作者谈《阿里巴巴Java开发手册(规约)》背后的故事
  5. gdb调试 程序退出没有堆栈信息([Inferior 1 (process 12867) exited with code 0177])
  6. Openwrt 18.06 iPhone XR usb tethering导致内核崩溃问题解决方案
  7. 利用Jsoup爬取网页内容
  8. Apache Velocity 模板语言 特殊字符${ $!{ 原样输出问题 转义符 # ! 无效
  9. 曾扬言 机器人合法公民_曾扬言“摧毁人类”的机器人索菲亚,现状如何?如果失控了咋办?...
  10. 若依的${params.dataScope}