Skip to content

Commit

Permalink
Replaced existing Trace Provider with a SharePoint 2010 diagnostics s…
Browse files Browse the repository at this point in the history
…ervice.
  • Loading branch information
ccoulson committed Jul 18, 2011
1 parent c00af57 commit b01f02e
Show file tree
Hide file tree
Showing 9 changed files with 208 additions and 230 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
using System.Runtime.InteropServices;

namespace Visigo.Sharepoint.FormsBasedAuthentication
{
class FBADiagnosticsService : SPDiagnosticsServiceBase
{

public static string AreaName = "SharePoint 2010 FBA Pack";

public static string ServiceName = "SharePoint 2010 FBA Pack Diagnostics Service";

public enum FBADiagnosticsCategory
{
General
} // enum MyDiagnosticsCategory

public FBADiagnosticsService()
: base(ServiceName, SPFarm.Local)
{
} // ctor()

public FBADiagnosticsService(string name, SPFarm parent)
: base(name, parent)
{
// SPDiagnosticsServiceBase.GetLocal() wants the default ctor and this one
} // ctor()

protected override bool HasAdditionalUpdateAccess()
{
// Without this SPDiagnosticsServiceBase.GetLocal<MyDiagnosticsService>()
// throws a SecurityException, see
// http://share2010.wordpress.com/tag/sppersistedobject/
return true;
} // HasAdditionalUpdateAccess()

public static FBADiagnosticsService Local
{
get
{
// SPUtility.ValidateFormDigest(); doesn't work here
if (SPContext.Current != null)
{
SPContext.Current.Web.AllowUnsafeUpdates = true;
}
// (Else assume this is called from a FeatureReceiver)
return SPDiagnosticsServiceBase.GetLocal<FBADiagnosticsService>();
}
} // Local

public void WriteTrace(ushort id, FBADiagnosticsCategory fbaDiagnosticsCategory, TraceSeverity traceSeverity, string message, params object[] data)
{
if (traceSeverity != TraceSeverity.None)
{
// traceSeverity==TraceSeverity.None would cause an ArgumentException:
// "Specified value is not supported for the severity parameter."
SPDiagnosticsCategory category = Local.Areas[AreaName].Categories[fbaDiagnosticsCategory.ToString()];
Local.WriteTrace(id, category, traceSeverity, message, data);
}
} // LogMessage()

protected override IEnumerable<SPDiagnosticsArea> ProvideAreas()
{
List<SPDiagnosticsCategory> categories = new List<SPDiagnosticsCategory>();
categories.Add(new SPDiagnosticsCategory(FBADiagnosticsCategory.General.ToString(), TraceSeverity.Verbose, EventSeverity.Verbose));

SPDiagnosticsArea area = new SPDiagnosticsArea(AreaName, 0, 0, false, categories);

List<SPDiagnosticsArea> areas = new List<SPDiagnosticsArea>();

areas.Add(area);

return areas;
} // ProvideAreas()

}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -181,27 +181,21 @@ public static bool IsWebAppFBAEnabled(SPSite site)
return (settings.AuthenticationMode == AuthenticationMode.Forms);
}

public static void LogError(string errorMessage, string errorCategory)
public static void LogError(string errorMessage, FBADiagnosticsService.FBADiagnosticsCategory errorCategory)
{
// log error to ULS log
TraceProvider.WriteTrace(0, TraceProvider.TraceSeverity.CriticalEvent, Guid.NewGuid(), Assembly.GetExecutingAssembly().FullName, "InternetExtranetEdition", errorCategory, errorMessage);
FBADiagnosticsService.Local.WriteTrace(0, errorCategory, TraceSeverity.High, errorMessage,null);
}

public static void LogError(Exception ex)
{
// create error message
string errorMessage = ex.Message + " " + ex.StackTrace;

// add any inner exceptions
Exception innerException = ex.InnerException;
while (innerException != null)
{
errorMessage += "Inner Error: " + innerException.Message + " " + innerException.StackTrace;
innerException = innerException.InnerException;
}

// log error
LogError(errorMessage, ex.GetType().ToString());
LogError(ex.ToString(), FBADiagnosticsService.FBADiagnosticsCategory.General);
}

public static void LogError(string errorMessage)
{
LogError(errorMessage, FBADiagnosticsService.FBADiagnosticsCategory.General);
}

public static void LogError(Exception ex, bool transferToErrorPage)
Expand Down
Loading

0 comments on commit b01f02e

Please sign in to comment.