Search Unity

Redirecting C# compilation errors to a text file

Discussion in 'Getting Started' started by nchw, Sep 18, 2017.

  1. nchw

    nchw

    Joined:
    Sep 18, 2017
    Posts:
    4
    Hello.
    I'm completely new to Unity and encountered an issue while writing a small editor customization.
    I would like to capture C# compilation errors that attached scripts caused and redirect the messages to a text file. I found the LogMessageReceived-family callbacks, but it doesn't seem to capture CSxxxx errors. Is there any way to do this, or am I doing something wrong? Debug.Log() can be captured just fine.
    Here's the minimum code:
    //Assets/Editor/UnityAccessibility.cs
    using UnityEngine;
    using UnityEditor;
    [InitializeOnLoad]
    public class UnityAccessibility{
    static UnityAccessibility(){
    Application.logMessageReceivedThreaded += WriteUnityLog;
    }
    private static void WriteUnityLog(string logString, string stackTrace, LogType type){
    System.IO.File.AppendAllText("C:\\git\\a.txt",type.ToString()+" : "+logString+'\n');
    }
    }
    Sorry for some tentative hard-codings.