Close() публичный Метод

public Close ( ) : void
Результат void
Пример #1
0
        // ユーザー・フレンドリなダイアログを表示するメソッド
        public static void ShowErrorMessage(Exception ex)
        {
            logger.TraceEvent(System.Diagnostics.TraceEventType.Critical,
                              0, ex.ToString());

            logger.Flush();
            logger.Close();

            MessageBox.Show("エラーが発生したため、エラーログ(log\\linearerror.log)を作成しました。\n" +
                            " お手数ですが問題解決のため、エラーログをFINALSTREAMにメールでお知らせください。\n" +
                            " ご協力お願いいたします。", "クリティカルエラー", MessageBoxButtons.OK, MessageBoxIcon.Error);

            //Application.Exit();
        }
Пример #2
0
 private void TraceToOutput()
 {
     TraceSource traceSource = new TraceSource("TraceSource", SourceLevels.All);
     traceSource.TraceInformation("Tracing");
     traceSource.TraceEvent(TraceEventType.Critical, 0, "Critical");
     traceSource.TraceData(TraceEventType.Information, 1, new object[] { "x", "y", "z" });
     traceSource.Flush();
     traceSource.Close();
 }
Пример #3
0
        public static void HowToUseTheTraceSourceClass()
        {
            TraceSource traceSource = new TraceSource("myTraceSource", SourceLevels.All);

            traceSource.TraceInformation("Tracing app");
            traceSource.TraceEvent(TraceEventType.Critical, 0, "Critical trace");
            traceSource.TraceData(TraceEventType.Information, 1, new object[] { "a", "b", "c" });

            traceSource.Flush();
            traceSource.Close();
        }
Пример #4
0
        public static void Main(string[] args)
        {
            TraceSource traceSource = new TraceSource("myTraceSource", SourceLevels.All);

            traceSource.TraceInformation("Tracing application...");
            traceSource.TraceEvent(TraceEventType.Critical, 0, "Critical trace");
            traceSource.TraceData(TraceEventType.Information, 1, new object[] { "a", "b", "c" });

            traceSource.Flush();
            traceSource.Close();
        }
Пример #5
0
        static void Main(string[] args)
        {
            TraceSource myTraceSource = new TraceSource("MyConsoleApp");

            myTraceSource.TraceEvent(TraceEventType.Error, 1, "Tracing Error Message.");
            myTraceSource.TraceEvent(TraceEventType.Warning, 2, "Tracing Warning Message.");
            myTraceSource.TraceEvent(TraceEventType.Information, 3, "Tracing Information.");
            myTraceSource.TraceEvent(TraceEventType.Verbose, 4, "Tracing Verbose Message.");
            myTraceSource.TraceEvent(TraceEventType.Critical, 5, "Tracing Critical Message.");

            myTraceSource.Close();
        }
Пример #6
0
 public static void DoTrace()
 {
     Stream outputFile = File.Create("tracefile.txt");
     TextWriterTraceListener textListener =
     new TextWriterTraceListener(outputFile);
     TraceSource traceSource = new TraceSource("myTraceSource",
     SourceLevels.All);
     traceSource.Listeners.Clear();
     traceSource.Listeners.Add(textListener);
     traceSource.TraceInformation("Trace output");
     traceSource.Flush();
     traceSource.Close();
 }
Пример #7
0
        static void Main(string[] args)
        {
            TraceSource traceSource = new TraceSource("myTraceSource", SourceLevels.All);

            traceSource.TraceInformation("Tracing application.");
            traceSource.TraceEvent(TraceEventType.Critical, 0, "Critical trace");
            traceSource.TraceData(TraceEventType.Information, 1, new object[] { "a", "b", "c" });

            traceSource.Flush();
            traceSource.Close();

            Console.WriteLine("Press a key to exit");
            Console.ReadKey();
        }
Пример #8
0
        private void TraceToFile()
        {
            Stream TrFile = File.Create("Hello_Debug_Trace.txt");
            TextWriterTraceListener txtLstnr =
                new TextWriterTraceListener(TrFile);

            TraceSource traceSource = new
                TraceSource("TraceSource", SourceLevels.All);
            traceSource.Listeners.Clear();
            traceSource.Listeners.Add(txtLstnr);
            traceSource.TraceInformation("Trace output");
            traceSource.Flush();
            traceSource.Close();
        }
Пример #9
0
        static void Main(string[] args)
        {
            using (Stream outputFile = File.Create("tracefile.txt"))
            {
                TextWriterTraceListener textListener = new TextWriterTraceListener(outputFile);

                TraceSource traceSource = new TraceSource("myTraceSource", SourceLevels.All);

                traceSource.Listeners.Clear();
                traceSource.Listeners.Add(textListener);

                traceSource.TraceInformation("trace output");

                traceSource.Flush();
                traceSource.Close();
            }
        }
Пример #10
0
        public static void HowToUseTheTraceListenerClass()
        {
            Stream outputFile = File.Create("traceFile.txt");
            TextWriterTraceListener textListener = new TextWriterTraceListener(outputFile);

            TraceSource traceSource = new TraceSource("myTraceSource", SourceLevels.All);

            traceSource.Listeners.Clear();
            traceSource.Listeners.Add(textListener);

            traceSource.TraceInformation("Tracing app");
            traceSource.TraceEvent(TraceEventType.Critical, 0, "Critical trace");
            traceSource.TraceData(TraceEventType.Information, 1, new object[] { "a", "b", "c" });

            traceSource.Flush();
            traceSource.Close();
        }
        private void SetLevel(SourceLevels level)
        {
            SourceLevels levels = this.FixLevel(level);

            this.level = levels;
            if (this.TraceSource != null)
            {
                this.haveListeners = this.TraceSource.Listeners.Count > 0;
                if ((this.TraceSource.Switch.Level != SourceLevels.Off) && (level == SourceLevels.Off))
                {
                    System.Diagnostics.TraceSource traceSource = this.TraceSource;
                    this.CreateTraceSource();
                    traceSource.Close();
                }
                this.tracingEnabled           = this.HaveListeners && (levels != SourceLevels.Off);
                this.TraceSource.Switch.Level = levels;
                this.shouldUseActivity        = (levels & SourceLevels.ActivityTracing) != SourceLevels.Off;
            }
        }
Пример #12
0
        static void Main(string[] args)
        {
            Stream outputFile = File.Create("tracefile.txt");
            TextWriterTraceListener textListener = new TextWriterTraceListener(outputFile);

            TraceSource traceSource = new TraceSource("myTraceSource", SourceLevels.All);

            traceSource.Listeners.Clear();
            traceSource.Listeners.Add(textListener);

            traceSource.TraceInformation("Trace output");

            traceSource.Flush();
            traceSource.Close();

            Console.WriteLine("tracefile.txt created in output directory.");
            Console.WriteLine("Press a key to exit");
            Console.ReadKey();
        }
Пример #13
0
        private void SetLevel(SourceLevels level)
        {
            SourceLevels sourceLevel = Microsoft.ServiceBus.Diagnostics.DiagnosticTrace.FixLevel(level);

            this.level = sourceLevel;
            if (this.TraceSource != null)
            {
                this.haveListeners = this.TraceSource.Listeners.Count > 0;
                if (this.TraceSource.Switch.Level != SourceLevels.Off && level == SourceLevels.Off)
                {
                    System.Diagnostics.TraceSource traceSource = this.TraceSource;
                    this.CreateTraceSource();
                    traceSource.Close();
                }
                this.tracingEnabled           = (!this.HaveListeners ? false : sourceLevel != SourceLevels.Off);
                this.TraceSource.Switch.Level = sourceLevel;
                this.shouldUseActivity        = (sourceLevel & SourceLevels.ActivityTracing) != SourceLevels.Off;
            }
        }
Пример #14
0
        static void Main(string[] args)
        {
            Debug.WriteLine("Starting application");
            Debug.Indent();
            int i = 1 + 2;
            Debug.Assert(i == 3);
            Debug.WriteLineIf(i > 0, "i is greater than 0");

            TraceSource traceSource = new TraceSource("myTraceSource", SourceLevels.All);
            traceSource.TraceInformation("Tracing application..");
            traceSource.TraceEvent(TraceEventType.Critical, 0, "Critical trace");
            traceSource.TraceData(TraceEventType.Information, 1,
            new object[] { "a", "b", "c" });
            traceSource.Flush();
            traceSource.Close();

            DoTrace();

            Console.ReadLine();
        }
Пример #15
0
        static void Main(string[] args)
        {
            TraceSource myTraceSource = new TraceSource("MyConsoleApp");

            myTraceSource.TraceEvent(TraceEventType.Error, 1, "Tracing Error Message.");
            myTraceSource.TraceEvent(TraceEventType.Warning, 2, "Tracing Warning Message.");
            myTraceSource.TraceEvent(TraceEventType.Information, 3, "Tracing Information.");
            myTraceSource.TraceEvent(TraceEventType.Verbose, 4, "Tracing Verbose Message.");
            myTraceSource.TraceEvent(TraceEventType.Critical, 5, "Tracing Critical Message.");

            string msg = String.Empty;
            Console.Write("Napisz komunikat do wysłania!" + Environment.NewLine);
            bool _go = true;
            while (_go)
            {
                msg = Console.ReadLine();
                if (msg.Contains("exit"))
                {
                    _go = false;
                }
                myTraceSource.TraceEvent(TraceEventType.Information, 3, msg);
            }
            myTraceSource.Close();
        }
Пример #16
0
        //based on: http://stackoverflow.com/questions/3303126/how-to-get-the-value-of-private-field-in-c
        //        and http://stackoverflow.com/questions/23664573/tracesource-and-tracelistener-quietly-fail-to-do-anything
        // safe to call multiple times
        private static void AttachToAllTraceSources(TraceListener yourListener)
        {
            List<string> sourceList = new List<string>();

            TraceSource ts = new TraceSource("foo");
            List<WeakReference> list = (List<WeakReference>)GetInstanceField(typeof(TraceSource), ts, "tracesources");
            for(int count = 0; count < list.Count; count++)
            {
                WeakReference weakReference = list[count];
                if(weakReference.IsAlive)
                {
                    TraceSource source = (weakReference.Target as TraceSource);
                    if(source != null && source.Name != "foo")
                    {
                        if(!source.Listeners.Contains(yourListener))	//This works after overriding Equals()
                        {
                            source.Listeners.Add(yourListener);
                            sourceList.Add(source.Name);
                        }
                    }
                }
            }
            ts.Close();

            _traceSource.TraceEvent(TraceEventType.Information, 57, "Jkh.TraceListenerRtf is listening to : {0}", string.Join(",",sourceList));
        }
Пример #17
0
        public void LogToEmailUsingDirectObjectOnlyResultsInOneMessage()
        {
            MockEmailTraceListener listener = new MockEmailTraceListener("[email protected];[email protected]", "*****@*****.**",
                                        "EntLib-Logging ->", "has occurred", "smtphost");

            TraceSource source = new TraceSource("unnamed", SourceLevels.All);
            source.Listeners.Add(listener);

            int numMessages = listener.MessagesSent;

            source.TraceData(TraceEventType.Error, 1, new TestCustomObject());
            source.Close();

            int newNumMessages = listener.MessagesSent;

            Assert.AreEqual(numMessages, newNumMessages - 1);
        }
Пример #18
0
        // Gets the name of the closest "parent" TraceRoute that has listeners, or null otherwise.
        private static TraceSource GetTraceSourceWithListeners_Locked(string name, SourceLevels sourceLevels)
        {
            string[] parts = name.Split(new char[] { '.' }, StringSplitOptions.None);

            List<string> namesToTest = new List<string>();
            StringBuilder sb = new StringBuilder();
            foreach (var part in parts)
            {
                if (sb.Length > 0)
                    sb.Append(".");
                sb.Append(part);

                string partialName = sb.ToString();
                namesToTest.Add(partialName);
            }

            namesToTest.Reverse();
            foreach (var testName in namesToTest)
            {
                TraceSource ts = null;
                ts = new TraceSource(testName, sourceLevels);
                // no listeners? skip
                if (ts.Listeners == null || ts.Listeners.Count == 0)
                {
                    ts.Close();
                    continue;
                }
                // more than one listener? use this TraceSource
                if (ts.Listeners.Count > 1)
                    return ts;
                TraceListener listener = ts.Listeners[0];
                // single listener isn't DefaultTraceListener? use this TraceRoute
                if (!(listener is DefaultTraceListener))
                    return ts;
                // single listener is DefaultTraceListener but isn't named Default? use this TraceRoute
                if (!string.Equals(listener.Name, "Default", StringComparison.Ordinal))
                    return ts;

                // not the TraceSource we're looking for, close it
                ts.Close();
            }

            // nothing found? no listeners are configured for any of the names, even the original,
            // so return null to signify failure
            return null;
        }
        public void LogToDatabaseUsingDirectObjectOnlyResultsInOneMessage()
        {
            FormattedDatabaseTraceListener listener = new FormattedDatabaseTraceListener(new SqlDatabase(connectionString), "WriteLog", "AddCategory", new TextFormatter("TEST{newline}TEST"));

            TraceSource source = new TraceSource("notfromconfig", SourceLevels.All);
            source.Listeners.Add(listener);
            int numMessages = GetNumberOfLogMessage("LoggingDb");

            source.TraceData(TraceEventType.Error, 1, new TestCustomObject());
            source.Close();

            int newNumMessages = GetNumberOfLogMessage("LoggingDb");

            Assert.AreEqual(numMessages, newNumMessages - 1);
        }
Пример #20
0
        public void LogToMsmqUsingDirectObjectOnlyResultsInOneMessage()
        {
            ILogFormatter formatter = new BinaryLogFormatter();
            MsmqTraceListener listener =
                new MsmqTraceListener("unnamed", CommonUtil.MessageQueuePath, formatter, MessagePriority.Low, true,
                                      MsmqTraceListenerData.DefaultTimeToBeReceived, MsmqTraceListenerData.DefaultTimeToReachQueue,
                                      false, false, false, MsmqTraceListenerData.DefaultTransactionType, new MockMsmqInterfaceFactory());
            TraceSource source = new TraceSource("unnamed", SourceLevels.All);
            source.Listeners.Add(listener);

            int numMessages = MockMsmqInterface.Instance.MessageCount;

            source.TraceData(TraceEventType.Error, 1, new TestCustomObject());
            source.Close();

            int newNumMessages = MockMsmqInterface.Instance.MessageCount;

            Assert.AreEqual(numMessages, newNumMessages - 1);
        }
Пример #21
0
		private static void LogExceptionInternal(string message, TraceEventType severity)
		{
			var traceSource = new TraceSource(Assembly.GetEntryAssembly().GetName().Name);
			traceSource.TraceEvent(severity, 0, message);
			traceSource.Flush();
			traceSource.Close();
		}
Пример #22
0
 private static void LogError(string tracesource, int id, string message)
 {
     TraceSource TraceSource = new TraceSource(tracesource);
     TraceSource.TraceData(TraceEventType.Error, id, message);
     TraceSource.Close();
 }
Пример #23
0
        /// <summary>
        /// Gets the closest "parent" TraceRoute that has listeners, or null otherwise
        /// </summary>
        /// <param name="name"></param>
        /// <param name="sourceLevels"></param>
        /// <returns></returns>
        private static TraceSource GetTraceSourceWithListenersSyncLock(string name, SourceLevels sourceLevels)
        {
            string[] splitters = name.Split(new char[] { '.' }, StringSplitOptions.None);
            List<string> nameSplitList = new List<string>();
            StringBuilder builder = new StringBuilder();

            foreach (string split in splitters)
            {
                if (builder.Length > 0)
                {
                    builder.Append(".");
                }

                builder.Append(split);

                string partialName = builder.ToString();
                nameSplitList.Add(partialName);
            }

            nameSplitList.Reverse();

            foreach (string nameSplit in nameSplitList)
            {
                TraceSource sourceTrace = null;
                sourceTrace = new TraceSource(nameSplit, sourceLevels);

                if (sourceTrace.Listeners == null || sourceTrace.Listeners.Count == 0)
                {
                    sourceTrace.Close();
                    continue;
                }

                if (sourceTrace.Listeners.Count > 1)
                {
                    return sourceTrace;
                }
                TraceListener listenerTrace = sourceTrace.Listeners[0];

                if (!(listenerTrace is DefaultTraceListener))
                {
                    return sourceTrace;
                }
                
                if (!string.Equals(listenerTrace.Name, "Default", StringComparison.Ordinal))
                {
                    return sourceTrace;
                }
                sourceTrace.Close();
            }

            return null;
        }
        public void ShouldFilterLog()
        {
            MockEmailTraceListener listener = new MockEmailTraceListener("[email protected];[email protected]", "*****@*****.**",
                                                                         "EntLib-Logging ->", "has occurred", "smtphost");

            listener.Filter = new EventTypeFilter(SourceLevels.Warning);

            TraceSource source = new TraceSource("unnamed", SourceLevels.Error);
            source.Listeners.Add(listener);

            source.TraceData(TraceEventType.Information, 1, new TestCustomObject());
            source.Close();

            Assert.AreEqual(0, listener.MessagesSent);
        }