1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
| using Microsoft.SharePoint.Administration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace xxxxxxxxx
{
/// <summary>
/// Used for logging into Uls in 2010
/// </summary>
public class ULSLog2013 : SPDiagnosticsServiceBase
{
public const string PRODUCT_NAME = "Votre produit";
private static ULSLog2013 _Current;
private ULSLog2013()
: base(PRODUCT_NAME, SPFarm.Local)
{
}
public static ULSLog2013 Current
{
get
{
if (_Current == null)
{
_Current = new ULSLog2013();
}
return _Current;
}
}
public static void Log(TraceSeverity traceSeverity, Exception ex)
{
SPDiagnosticsCategory category = ULSLog2013.Current.Areas[PRODUCT_NAME].Categories["Error"];
ULSLog2013.Current.WriteTrace(0, category, TraceSeverity.High, ex.Message);
ULSLog2013.Current.WriteTrace(0, category, TraceSeverity.High, ex.ToString());
}
public static void Log(TraceSeverity traceSeverity, string message, Exception ex)
{
SPDiagnosticsCategory category = ULSLog2013.Current.Areas[PRODUCT_NAME].Categories["Error"];
ULSLog2013.Current.WriteTrace(0, category, TraceSeverity.High, ex.Message);
ULSLog2013.Current.WriteTrace(0, category, TraceSeverity.High, ex.ToString());
}
public static void LogDebug(string message)
{
SPDiagnosticsCategory category = ULSLog2013.Current.Areas[PRODUCT_NAME].Categories["Debugging"];
ULSLog2013.Current.WriteTrace(1, category, TraceSeverity.Verbose, message);
}
public static void LogError(Exception ex)
{
SPDiagnosticsCategory category = ULSLog2013.Current.Areas[PRODUCT_NAME].Categories["Error"];
ULSLog2013.Current.WriteTrace(0, category, TraceSeverity.High, ex.Message);
ULSLog2013.Current.WriteTrace(0, category, TraceSeverity.High, ex.ToString());
}
public static void LogError(Exception ex, string message)
{
SPDiagnosticsCategory category = ULSLog2013.Current.Areas[PRODUCT_NAME].Categories["Error"];
ULSLog2013.Current.WriteTrace(0, category, TraceSeverity.High, message);
ULSLog2013.Current.WriteTrace(0, category, TraceSeverity.High, ex.ToString());
}
public static void LogError(string message, string stackTrace)
{
SPDiagnosticsCategory category = ULSLog2013.Current.Areas[PRODUCT_NAME].Categories["Error"];
ULSLog2013.Current.WriteTrace(0, category, TraceSeverity.High, message + "Stacktrace : " + stackTrace);
}
public static void LogMessage(string message)
{
SPDiagnosticsCategory category = ULSLog2013.Current.Areas[PRODUCT_NAME].Categories["Logging"];
ULSLog2013.Current.WriteTrace(1, category, TraceSeverity.Verbose, message);
}
public static void LogWarning(string message)
{
SPDiagnosticsCategory category = ULSLog2013.Current.Areas[PRODUCT_NAME].Categories["Warning"];
ULSLog2013.Current.WriteTrace(1, category, TraceSeverity.Medium, message);
}
protected override IEnumerable<SPDiagnosticsArea> ProvideAreas()
{
List<SPDiagnosticsArea> areas = new List<SPDiagnosticsArea>
{
new SPDiagnosticsArea(PRODUCT_NAME, new List<SPDiagnosticsCategory>
{
new SPDiagnosticsCategory("Error", TraceSeverity.High, EventSeverity.Error),
new SPDiagnosticsCategory("Warning", TraceSeverity.Medium, EventSeverity.Warning),
new SPDiagnosticsCategory("Logging", TraceSeverity.Verbose, EventSeverity.Verbose),
new SPDiagnosticsCategory("Debugging", TraceSeverity.Verbose, EventSeverity.Verbose)
})
};
return areas;
}
private string MapTraceSeverity(TraceSeverity traceSeverity)
{
switch (traceSeverity)
{
case TraceSeverity.High: return "Error";
case TraceSeverity.Medium: return "Warning";
default:
case TraceSeverity.Verbose:
return "Debugging";
}
}
}
} |
Partager