Example #1
0
        public static void Open(string logFolderPath, string logFileName, string prefix, Dictionary <ushort, string> sourceIDs)
        {
            logFolderPath = logFolderPath.TrimEnd(Path.DirectorySeparatorChar);
            logFolderPath = logFolderPath.TrimEnd(Path.AltDirectorySeparatorChar);
            if (sourceIDs == null)
            {
                throw new NullReferenceException();
            }
            if (sources == null || (currentLogPath != logFolderPath + Path.DirectorySeparatorChar + logFileName))
            {
                Close();

                if (File.Exists(logFolderPath + Path.DirectorySeparatorChar + logFileName))
                {
                    try
                    {
                        File.Delete(logFolderPath + Path.DirectorySeparatorChar + logFileName);
                    }
                    catch
                    {
                    }
                }
                //Console Normal
                if (CLR_PSE_Utils.IsWindows())
                {
                    stdOut = new TextWriterTraceListener(new CLR_PSE_NativeLoggerWin(false));
                }
                else
                {
                    stdOut = new TextWriterTraceListener(Console.Out);
                }
                stdOut.Filter = new EventTypeFilter(consoleStdLevel); //information
                stdOut.Name   = "StdOut";
                //Console Error
                if (CLR_PSE_Utils.IsWindows())
                {
                    stdErr = new TextWriterTraceListener(new CLR_PSE_NativeLoggerWin(true));
                }
                else
                {
                    stdErr = new TextWriterTraceListener(Console.Error);
                }
                stdErr.Filter  = new EventTypeFilter(consoleErrLevel);
                stdErr.Name    = "StdErr";
                currentLogPath = logFolderPath + Path.DirectorySeparatorChar + logFileName;
                //Text File
                try
                {
                    fileAll        = new TextWriterTraceListener(currentLogPath);
                    fileAll.Filter = new EventTypeFilter(FileLevel);
                    fileAll.Name   = "File";
                    //defualtSource.Listeners.Add(textListener);
                }
                catch (Exception e)
                {
                    //Console.Error.WriteLine("Failed to Open Log File :" + e.ToString());
                    stdErr.WriteLine("Failed to Open Log File :" + e.ToString());
                }
                //Create sources
                sources = new Dictionary <int, TraceSource>();
                //Defualt Sources
                AddSource(UNKOWN, "UnkownSource", prefix);
                SetSourceLogLevel(SourceLevels.All, UNKOWN);
                SetSourceUseStdOut(true, UNKOWN);
                AddSource(ERRTRAP, "ErrorTrapper", prefix);
                SetSourceUseStdOut(true, ERRTRAP);

                foreach (KeyValuePair <ushort, string> sourceID in sourceIDs)
                {
                    AddSource(sourceID.Key, sourceID.Value, prefix);
                }
            }
        }
Example #2
0
 public static void DEV9setLogDir(IntPtr dir)
 {
     Plugin.SetLogDir(CLR_PSE_Utils.MarshalDirectoryString(dir));
 }