Exemple #1
0
        /// <summary>
        /// Replaces the format item in a specified <see cref="System.String"/> with the text equivalent
        /// of the value of a corresponding <see cref="System.Object"/> instance in a specified array.
        /// A specified parameter supplies culture-specific formatting information.
        /// </summary>
        /// <param name="provider">An <see cref="System.IFormatProvider"/> that supplies culture-specific formatting information.</param>
        /// <param name="format">A <see cref="System.String"/> containing zero or more format items.</param>
        /// <param name="args">An <see cref="System.Object"/> array containing zero or more objects to format.</param>
        /// <returns>
        /// A copy of format in which the format items have been replaced by the <see cref="System.String"/>
        /// equivalent of the corresponding instances of <see cref="System.Object"/> in args.
        /// </returns>
        /// <remarks>
        /// <para>
        /// This method does not throw exceptions. If an exception thrown while formatting the result the
        /// exception and arguments are returned in the result string.
        /// </para>
        /// </remarks>
        private static string StringFormat(IFormatProvider provider, string format, params object[] args)
        {
            try
            {
                // The format is missing, log null value
                if (format == null)
                {
                    return(null);
                }

                // The args are missing - should not happen unless we are called explicitly with a null array
                if (args == null)
                {
                    return(format);
                }

                // Try to format the string
                return(String.Format(provider, format, args));
            }
            catch (Exception ex)
            {
                LogLog.Warn(declaringType, "Exception while rendering format [" + format + "]", ex);
                return(StringFormatError(ex, format, args));
            }
#if !NET_2_0 && !MONO_2_0
            catch
            {
                LogLog.Warn(declaringType, "Exception while rendering format [" + format + "]");
                return(StringFormatError(null, format, args));
            }
#endif
        }
Exemple #2
0
        /// <summary>
        /// Get the PropertiesDictionary stored in the LocalDataStoreSlot for this thread.
        /// </summary>
        /// <param name="create">create the dictionary if it does not exist, otherwise return null if is does not exist</param>
        /// <returns>the properties for this thread</returns>
        /// <remarks>
        /// <para>
        /// The collection returned is only to be used on the calling thread. If the
        /// caller needs to share the collection between different threads then the
        /// caller must clone the collection before doings so.
        /// </para>
        /// </remarks>
        internal PropertiesDictionary GetProperties(bool create)
        {
            if (!m_disabled)
            {
                try
                {
                    PropertiesDictionary properties = GetLogicalProperties();
                    if (properties == null && create)
                    {
                        properties = new PropertiesDictionary();
                        SetLogicalProperties(properties);
                    }
                    return(properties);
                }
                catch (SecurityException secEx)
                {
                    m_disabled = true;

                    // Thrown if we don't have permission to read or write the CallContext
                    LogLog.Warn(declaringType, "SecurityException while accessing CallContext. Disabling LogicalThreadContextProperties", secEx);
                }
            }

            // Only get here is we are disabled because of a security exception
            if (create)
            {
                return(new PropertiesDictionary());
            }
            return(null);
        }
 /// <summary>
 /// Get the PropertiesDictionary stored in the LocalDataStoreSlot for this thread.
 /// </summary>
 /// <param name="create">create the dictionary if it does not exist, otherwise return null if is does not exist</param>
 /// <returns>the properties for this thread</returns>
 /// <remarks>
 /// <para>
 /// The collection returned is only to be used on the calling thread. If the
 /// caller needs to share the collection between different threads then the
 /// caller must clone the collection before doings so.
 /// </para>
 /// </remarks>
 internal PropertiesDictionary GetProperties(bool create)
 {
     if (!m_disabled)
     {
         try
         {
             PropertiesDictionary propertiesDictionary = GetLogicalProperties();
             if (propertiesDictionary == null && create)
             {
                 propertiesDictionary = new PropertiesDictionary();
                 SetLogicalProperties(propertiesDictionary);
             }
             return(propertiesDictionary);
         }
         catch (SecurityException exception)
         {
             m_disabled = true;
             LogLog.Warn(declaringType, "SecurityException while accessing CallContext. Disabling LogicalThreadContextProperties", exception);
         }
     }
     if (create)
     {
         return(new PropertiesDictionary());
     }
     return(null);
 }
        /// <summary>
        /// Loop as long as not <see cref="m_stop"/>
        /// </summary>
        private void Run()
        {
            var maxSnooze = TimeSpan.FromMilliseconds(500);

            try
            {
                lock (m_control_locker)
                {
                    while (!m_stop)
                    {
                        while (!m_stop && m_calls.Count == 0)
                        {
                            // suspend activity if there's nothing to do
                            Monitor.Wait(m_control_locker, maxSnooze);
                            Monitor.PulseAll(m_control_locker);
                        }

                        if (m_stop)
                        {
                            break;
                        }

                        var snooze = ExecuteSchedule(maxSnooze);

                        Monitor.Wait(m_control_locker, snooze);
                        Monitor.PulseAll(m_control_locker);
                    }
                }
            }
            catch (ThreadAbortException tax)
            {
#if LOG4NET_1_2_10_COMPATIBLE
                LogLog.Error("Alive.Run() aborted.", tax);
#else
                LogLog.Error(GetType(), "Alive.Run() aborted.", tax);
#endif
            }
            catch (Exception x)
            {
                m_stop = true;

#if LOG4NET_1_2_10_COMPATIBLE
                LogLog.Error("Alive.Run() failed.", x);
#else
                LogLog.Error(GetType(), "Alive.Run() failed.", x);
#endif
            }
            finally
            {
#if LOG4NET_1_2_10_COMPATIBLE
                LogLog.Warn("Alive.Run() finished.");
#else
                LogLog.Warn(GetType(), "Alive.Run() finished.");
#endif
            }
        }
Exemple #5
0
 private static string StringFormat(IFormatProvider provider, string format, params object[] args)
 {
     try
     {
         return((format != null) ? ((args != null) ? string.Format(provider, format, args) : format) : null);
     }
     catch (Exception exception)
     {
         LogLog.Warn(declaringType, "Exception while rendering format [" + format + "]", exception);
         return(StringFormatError(exception, format, args));
     }
 }
 /// <summary>
 /// Replaces the format item in a specified <see cref="T:System.String" /> with the text equivalent
 /// of the value of a corresponding <see cref="T:System.Object" /> instance in a specified array.
 /// A specified parameter supplies culture-specific formatting information.
 /// </summary>
 /// <param name="provider">An <see cref="T:System.IFormatProvider" /> that supplies culture-specific formatting information.</param>
 /// <param name="format">A <see cref="T:System.String" /> containing zero or more format items.</param>
 /// <param name="args">An <see cref="T:System.Object" /> array containing zero or more objects to format.</param>
 /// <returns>
 /// A copy of format in which the format items have been replaced by the <see cref="T:System.String" />
 /// equivalent of the corresponding instances of <see cref="T:System.Object" /> in args.
 /// </returns>
 /// <remarks>
 /// <para>
 /// This method does not throw exceptions. If an exception thrown while formatting the result the
 /// exception and arguments are returned in the result string.
 /// </para>
 /// </remarks>
 private static string StringFormat(IFormatProvider provider, string format, params object[] args)
 {
     try
     {
         if (format == null)
         {
             return(null);
         }
         if (args == null)
         {
             return(format);
         }
         return(string.Format(provider, format, args));
     }
     catch (Exception ex)
     {
         LogLog.Warn(declaringType, "Exception while rendering format [" + format + "]", ex);
         return(StringFormatError(ex, format, args));
     }
 }