Пример #1
0
        public static TraceListenerRtf InstallTraceListener(RichTextBox richTextBoxOutput)
        {
            TraceListenerRtf newTraceListener = new TraceListenerRtf(richTextBoxOutput);
            Trace.Listeners.Add(newTraceListener);

            AttachToAllTraceSources(newTraceListener);

            return newTraceListener;
        }
Пример #2
0
 private void checkBoxHookUpTraceListener_CheckedChanged(object sender, EventArgs e)
 {
     if(checkBoxHookUpTraceListener.Checked)
     {
         myListener = TraceListenerRtf.InstallTraceListener(richTextBoxTraces);
         myListener.LogLevel = TraceEventType.Verbose;
     }
     else
     {
         if(myListener != null)
         {
             TraceListenerRtf.UninstallTraceListener(myListener);
             myListener.Dispose();
             myListener = null;
         }
     }
 }
Пример #3
0
        private void FormMain_Load(object sender, EventArgs e)
        {
            //			myListener = TraceListenerRtf.InstallTraceListener(richTextBoxTraces);

            comboBoxTraceLevel.DataSource = Enum.GetNames(typeof(TraceEventType));
            comboBoxSwitchValue.DataSource = Enum.GetNames(typeof(SourceLevels));

            using(MySettings settings = new MySettings())
            {
                string myValue = settings.GetSetting<string>("MySettingName1", "MySettingValueDefault1");

                settings.PutSetting("MySettingName2", "MySettingValue2");
                settings.PutSetting(MySettings.SomeSettingName, MySettings.SomeSettingDefaultValue);

                string myValue2 = settings.GetSetting<string>("MySettingName2", "MySettingValueDefault2");
                double myValueDouble2 = settings.GetSetting(MySettings.SomeSettingName, MySettings.SomeSettingDefaultValue);

                settings.PutSetting("MyIntArray", new int[] { 1, 2, 3, 4 });
                int[] myIntArray = settings.GetSetting("MyIntArray", new int[] { });

                settings.PutSetting("MyStringArray", new string[] { "one", "two", "three", "four" });
                string[] myStringArray = settings.GetSetting("MyStringArray", new string[] { "blah", "Blah" });

                settings.PutSetting("MyStringList", new List<string> { "test1", "Test2", "Test3" } );
                List<string> myStringList = settings.GetSetting("MyStringList", new List<string>());

                settings.PutSetting("MyDictionary", new SerializableDictionary<int, string> { [0]="test0", [2]="Test2", [99]="Test99" });
                SerializableDictionary<int, string> myDictionary = settings.GetSetting("MyDictionary", new SerializableDictionary<int, string>());

                settings.PutSetting("MyGuid", Guid.NewGuid());
                Guid myGuid = settings.GetSetting("MyGuid", new Guid());

                settings.PutSetting("MyDecimal", 99.571M);
                Decimal myDecimal = settings.GetSetting("MyDecimal", 0.0M);

                settings.PutSetting("MyPoint", new Point(4, 5));
                Point myPoint = settings.GetSetting("MyPoint", new Point(0, 0));

                settings.PutSetting("MySize", new Size(5, 5));
                Size mySize = settings.GetSetting("MySize", new Size(0, 0));

                settings.PutSetting("MyEnum", MyEnum.Enum3);
                MyEnum myEnum = settings.GetSetting("MyEnum", MyEnum.Value1);

                string[] myArray = settings.GetSetting(MySettings.MyArrayName, settings.MyArrayDefault);
                settings.PutSetting(MySettings.MyArrayName, new string[] { });
                string[] myArray2 = settings.GetSetting(MySettings.MyArrayName, settings.MyArrayDefault);

                settings.RestoreWindowPlacement(this);
                settings.RestoreColumnWidths(listView1);

                splitContainer1.SplitterDistance = settings.GetSetting(MySettings.SplitterDistanceName, MySettings.SplitterDistanceDefaultValue);
                textBoxTraceText.Text = settings.GetSetting(MySettings.TraceTextName, MySettings.TraceTextDefaultValue);

                comboBoxTraceLevel.SelectedItem = settings.GetSetting(MySettings.TraceLevelName, MySettings.TraceLevelDefaultValue);
                comboBoxSwitchValue.SelectedItem = settings.GetSetting(MySettings.SwitchValueName, MySettings.SwitchValueDefaultValue);

                Task t = Task.Run(async delegate
                {
                    await Task.Delay(TimeSpan.FromSeconds(5));
                    _traceSource2.TraceEvent(TraceEventType.Information, 57, "Second add:");
                    myListener = TraceListenerRtf.InstallTraceListener(richTextBoxTraces);
                    myListener.LogLevel = TraceEventType.Verbose;
                    _traceSource.TraceEvent(TraceEventType.Information, 57, "Added after 5 seconds");
                });
            }
        }
Пример #4
0
 public static void UninstallTraceListener(TraceListenerRtf myListener)
 {
     RemoveFromAllTraceSources(myListener);
 }