Sdl.Web.Common/Logging/Tracer.cs
/// <summary>
/// Converts the parameter supplied to the Tracer to a string and limit the value to the in configuration defined number of characters.
/// </summary>
/// <param name="param">The parameter to convert.</param>
/// <returns>A string that contains the value of the supplied parameter.</returns>
Converts the parameter supplied to the Tracer to a string and limit the value to the in configuration defined number of characters.
Converts the parameter supplied to the Tracer to a string and limit the value to the in configuration defined number of characters .
internal static string ConvertParameterToString(object param)
        {
            if (param == null)
            {
                return "null";
            }
            int resultLimit = 64; 
            bool isConverted = false;
            string result = param.ToString();
            if (param is string)
            {
                result = "\"" + param + "\"";
                isConverted = true;
            }
            if (param is XmlNode)
            {
                result = ((XmlNode)param).OuterXml;
                isConverted = true;
            }
            if (!isConverted && param is IEnumerable)
            {
                string[] itemStrings = ((IEnumerable)param).Cast<object>().Select(p => ConvertParameterToString(p)).ToArray();
                result = string.Join("; ", itemStrings);
            }
            if (result != null)
            {
                int length = result.Length;
                if (length > resultLimit && resultLimit != -1)
                {
                    result = result.Substring(0, resultLimit);
                    result += "…";
                    if (result.StartsWith("\"") && !result.EndsWith("\""))
                    {
                        result += "\"";
                    }
                }
            }
            return result;
        }
internal static string ConvertParameterToString ( object param ) { if ( param == null ) { return " " ; } int resultLimit = 64 ; bool isConverted = false ; string result = param . ToString ( ) ; if ( param is string ) { result = " \" " + param + " \" " ; isConverted = true ; } if ( param is XmlNode ) { result = ( ( XmlNode ) param ) . OuterXml ; isConverted = true ; } if ( ! isConverted && param is IEnumerable ) { string [ ] itemStrings = ( ( IEnumerable ) param ) . Cast < object > ( ) . Select ( p => ConvertParameterToString ( p ) ) . ToArray ( ) ; result = string . Join ( " " , itemStrings ) ; } if ( result != null ) { int length = result . Length ; if ( length > resultLimit && resultLimit != - 1 ) { result = result . Substring ( 0 , resultLimit ) ; result += " if ( result . StartsWith ( " \" " ) && ! result . EndsWith ( " \" " ) ) { result += " \" " ; } } } return result ; }
Converts the parameter supplied to the Tracer to a string and limit the value to the in configuration defined number of characters.
Converts the parameter supplied to the Tracer to a string and limit the value to the in configuration defined number of characters .
// The resultlimit for truncation can have a default value for all types. If it is not set, no truncation should be done. // TODO: _commonConfigSection.TracingSettings.ParameterValueTruncation.Default; //ParameterTypeElement element = (from ParameterTypeElement item in _commonConfigSection.TracingSettings.ParameterValueTruncation.ParameterTypes //                                where Type.GetType(item.Type + (String.IsNullOrEmpty(item.Assembly) ? String.Empty : ", " + item.Assembly)).IsAssignableFrom(param.GetType()) //                                select item).FirstOrDefault(); //// The resultlimit for truncation can also be set per item. If the item is defined, use the maxLength value. If there is no maxLength defined, no truncation should be done. //if (element != null) //{ //    resultLimit = element.MaxLength; //} //if (resultLimit == 0) //{ //    return "…"; //} // Almost everything is a IEnumerable // First test if we already converted the parameter // Limit the result (only when there is a result limit defined)
A string that contains the value of the supplied parameter.
A string that contains the value of the supplied parameter .
param
object
The parameter to convert.
The parameter to convert .