StackTraceDetailPatternConverter.cs 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. *
  3. * Licensed to the Apache Software Foundation (ASF) under one
  4. * or more contributor license agreements. See the NOTICE file
  5. * distributed with this work for additional information
  6. * regarding copyright ownership. The ASF licenses this file
  7. * to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance
  9. * with the License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing,
  14. * software distributed under the License is distributed on an
  15. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16. * KIND, either express or implied. See the License for the
  17. * specific language governing permissions and limitations
  18. * under the License.
  19. *
  20. */
  21. #if !NETCF
  22. using System;
  23. using System.Collections;
  24. using System.Text;
  25. using log4net.Util;
  26. using log4net.Core;
  27. namespace log4net.Layout.Pattern
  28. {
  29. /// <summary>
  30. /// Write the caller stack frames to the output
  31. /// </summary>
  32. /// <remarks>
  33. /// <para>
  34. /// Writes the <see cref="LocationInfo.StackFrames"/> to the output writer, using format:
  35. /// type3.MethodCall3(type param,...) > type2.MethodCall2(type param,...) > type1.MethodCall1(type param,...)
  36. /// </para>
  37. /// </remarks>
  38. /// <author>Adam Davies</author>
  39. internal class StackTraceDetailPatternConverter : StackTracePatternConverter
  40. {
  41. internal override string GetMethodInformation(MethodItem method)
  42. {
  43. string returnValue="";
  44. try
  45. {
  46. string param = "";
  47. string[] names = method.Parameters;
  48. StringBuilder sb = new StringBuilder();
  49. if (names != null && names.GetUpperBound(0) > 0)
  50. {
  51. for (int i = 0; i <= names.GetUpperBound(0); i++)
  52. {
  53. sb.AppendFormat("{0}, ", names[i]);
  54. }
  55. }
  56. if (sb.Length > 0)
  57. {
  58. sb.Remove(sb.Length - 2, 2);
  59. param = sb.ToString();
  60. }
  61. returnValue=base.GetMethodInformation(method) + "(" + param + ")";
  62. }
  63. catch (Exception ex)
  64. {
  65. LogLog.Error(declaringType, "An exception ocurred while retreiving method information.", ex);
  66. }
  67. return returnValue;
  68. }
  69. #region Private Static Fields
  70. /// <summary>
  71. /// The fully qualified type of the StackTraceDetailPatternConverter class.
  72. /// </summary>
  73. /// <remarks>
  74. /// Used by the internal logger to record the Type of the
  75. /// log message.
  76. /// </remarks>
  77. private readonly static Type declaringType = typeof(StackTracePatternConverter);
  78. #endregion Private Static Fields
  79. }
  80. }
  81. #endif