Exemple #1
0
        // Shows how to enable Speech SDK trace logging to memory. Memory logger keeps logging into a fixed-size
        // memory buffer (a "ring" buffer). At any pointer in time, when an issue occurs, the application
        // can dump the whole content of the memory buffer in one of several formats. For example, an
        // application using Speech SDK for speech recognition, may want to dump the content of the
        // logging memory buffer to file for one or more unexpected CancellationErrorCode values received
        // (instead of a recognition result).
        // Microsoft may ask you to collect logs using MemoryLogger in order to investigate an issue you reported,
        // and will guide you on when to do the dump.
        public static void MemoryLoggerWithOrWithoutFilter()
        {
            // Optional - Apply a filter, such that only traces that contain either one of the
            // filter strings will be logged. Microsoft will provide the filter when relevant.

            /*
             * string[] filters = { "YourFirstString", "YourSecondString" };
             * MemoryLogger.SetFilters(filters);
             */

            // Turn on logging to memory
            MemoryLogger.Start();

            // Do your Speech SDK calls here... for example:
            SpeechConfig     config     = SpeechConfig.FromSubscription("YourSubscriptionKey", "YourServiceRegion");
            SpeechRecognizer recognizer = new SpeechRecognizer(config);

            // Define the full path and name of a log file on your local disk
            string logFile = "speech-sdk-log.txt";

            // At any time (while still logging or after logging is stopped) you can dump the
            // recent traces from memory to a file:
            MemoryLogger.Dump(logFile);

            // Or dump to any object that is derived from System.IO.TextWriter. For example, System.Console.Out,
            // which will enable logging to your console windows:
            MemoryLogger.Dump(System.Console.Out);

            // Or dump to a vector of strings, and see the results on the console:
            List <string> messages = MemoryLogger.Dump().ToList <string>();

            Console.WriteLine("Here are the logs we captured:");
            foreach (string message in messages)
            {
                Console.Write(message);
            }

            // Stop logging to memory
            MemoryLogger.Stop();

            // Clear filters if previously set
            MemoryLogger.SetFilters();
        }