コード例 #1
0
        // Must be a separated method that is called by all other WriteLine methods otherwise calling method cannot be determined.
        private void WriteLineInternal(string message, string category)
        {
            if (string.IsNullOrEmpty(message))
            {
                throw new ArgumentNullException("message");
            }

            if (string.IsNullOrEmpty(category))
            {
                throw new ArgumentNullException("category");
            }

            MethodBase currentMethod = RadoslavFileTraceListener.GetCallingMethod();

            message = string.Join(
                "|",
                DateTime.UtcNow.ToString("yyyy\\/MM\\/dd hh:mm:ss.fffffff", CultureInfo.InvariantCulture),  // Sortable format with milliseconds.
                category.ToUpperInvariant(),
                currentMethod.DeclaringType.Name,
                currentMethod.Name,
                Thread.CurrentThread.ManagedThreadId,
                message);

            base.WriteLine(message);
        }
コード例 #2
0
        /// <summary>
        /// Creates a new instance of the <see cref="RadoslavFileTraceListener"/> class with a specified file name and
        /// adds it to the <see cref="Trace"/>.<see cref="Trace.Listeners"/> collection.
        /// </summary>
        /// <param name="fileName">The log file name.</param>
        /// <returns>The newly created <see cref="RadoslavFileTraceListener"/> instance.</returns>
        public static RadoslavFileTraceListener Add(string fileName)
        {
            RadoslavFileTraceListener result = new RadoslavFileTraceListener(fileName);

            Trace.Listeners.Add(result);

            return(result);
        }
コード例 #3
0
        /// <summary>
        /// Creates a new instance of the <see cref="RadoslavFileTraceListener"/> class with a temp file name and
        /// adds it to the <see cref="Trace"/>.<see cref="Trace.Listeners"/> collection.
        /// </summary>
        /// <returns>The newly created <see cref="RadoslavFileTraceListener"/> instance.</returns>
        public static RadoslavFileTraceListener Add()
        {
            RadoslavFileTraceListener result = new RadoslavFileTraceListener();

            Trace.Listeners.Add(result);

            return(result);
        }
コード例 #4
0
        /// <summary>
        /// Changes the underlying log file name.
        /// </summary>
        /// <remarks>This method removes the current <see cref="RadoslavFileTraceListener"/> instance from the
        /// <see cref="Trace"/>.<see cref="Trace.Listeners"/> collection, renames the old file to <paramref name="newFileName"/>,
        /// and creates a new <see cref="RadoslavFileTraceListener"/> instance logging to the new file name.</remarks>
        /// <param name="newFileName">The new file name.</param>
        /// <returns>A new <see cref="RadoslavFileTraceListener"/> instance with the specified file name.</returns>
        public RadoslavFileTraceListener ChangeFileName(string newFileName)
        {
            this.Flush();

            Trace.Listeners.Remove(this);

            this.Close();

            string logFileFolder = Path.GetDirectoryName(newFileName);

            if (!Directory.Exists(logFileFolder))
            {
                Directory.CreateDirectory(logFileFolder);
            }

            File.Move(this.fileName, newFileName);

            RadoslavFileTraceListener result = new RadoslavFileTraceListener(newFileName);

            Trace.Listeners.Add(result);

            return(result);
        }