summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--samples/Consumer/Global.asax3
-rw-r--r--samples/InfoCardRelyingParty/App_Code/Logging.cs20
-rw-r--r--samples/InfoCardRelyingParty/App_Code/TracePageAppender.cs11
-rw-r--r--samples/InfoCardRelyingParty/Global.asax58
-rw-r--r--samples/InfoCardRelyingParty/TracePage.aspx18
-rw-r--r--samples/InfoCardRelyingParty/TracePage.aspx.cs21
-rw-r--r--samples/InfoCardRelyingParty/web.config20
-rw-r--r--samples/RelyingPartyWebForms/Global.asax.cs4
8 files changed, 151 insertions, 4 deletions
diff --git a/samples/Consumer/Global.asax b/samples/Consumer/Global.asax
index 3e06b29..fa4ca9b 100644
--- a/samples/Consumer/Global.asax
+++ b/samples/Consumer/Global.asax
@@ -13,8 +13,7 @@
}
void Application_Error(object sender, EventArgs e) {
- // Code that runs when an unhandled error occurs
-
+ Logging.Logger.ErrorFormat("An unhandled exception was raised. Details follow: {0}", HttpContext.Current.Server.GetLastError());
}
void Session_Start(object sender, EventArgs e) {
diff --git a/samples/InfoCardRelyingParty/App_Code/Logging.cs b/samples/InfoCardRelyingParty/App_Code/Logging.cs
new file mode 100644
index 0000000..8e0da06
--- /dev/null
+++ b/samples/InfoCardRelyingParty/App_Code/Logging.cs
@@ -0,0 +1,20 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Web;
+
+/// <summary>
+/// Logging tools for this sample.
+/// </summary>
+public static class Logging {
+ /// <summary>
+ /// An application memory cache of recent log messages.
+ /// </summary>
+ public static StringBuilder LogMessages = new StringBuilder();
+
+ /// <summary>
+ /// The logger for this sample to use.
+ /// </summary>
+ public static log4net.ILog Logger = log4net.LogManager.GetLogger("DotNetOpenAuth.InfoCardRelyingParty");
+}
diff --git a/samples/InfoCardRelyingParty/App_Code/TracePageAppender.cs b/samples/InfoCardRelyingParty/App_Code/TracePageAppender.cs
new file mode 100644
index 0000000..93ec9e3
--- /dev/null
+++ b/samples/InfoCardRelyingParty/App_Code/TracePageAppender.cs
@@ -0,0 +1,11 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Web;
+
+public class TracePageAppender : log4net.Appender.AppenderSkeleton {
+ protected override void Append(log4net.Core.LoggingEvent loggingEvent) {
+ StringWriter sw = new StringWriter(Logging.LogMessages);
+ Layout.Format(sw, loggingEvent);
+ }
+}
diff --git a/samples/InfoCardRelyingParty/Global.asax b/samples/InfoCardRelyingParty/Global.asax
new file mode 100644
index 0000000..4d35280
--- /dev/null
+++ b/samples/InfoCardRelyingParty/Global.asax
@@ -0,0 +1,58 @@
+<%@ Application Language="C#" %>
+<%@ Import Namespace="System.IO" %>
+
+<script RunAt="server">
+ void Application_Start(object sender, EventArgs e) {
+ log4net.Config.XmlConfigurator.Configure();
+ Logging.Logger.Info("Sample starting...");
+ }
+
+ void Application_End(object sender, EventArgs e) {
+ Logging.Logger.Info("Sample shutting down...");
+ // this would be automatic, but in partial trust scenarios it is not.
+ log4net.LogManager.Shutdown();
+ }
+
+ void Application_Error(object sender, EventArgs e) {
+ Logging.Logger.ErrorFormat("An unhandled exception was raised. Details follow: {0}", HttpContext.Current.Server.GetLastError());
+ }
+
+ void Application_BeginRequest(object sender, EventArgs e) {
+ Logging.Logger.DebugFormat("Processing {0} on {1} ", Request.HttpMethod, stripQueryString(Request.Url));
+ if (Request.QueryString.Count > 0) {
+ Logging.Logger.DebugFormat("Querystring follows: \n{0}", ToString(Request.QueryString));
+ }
+ if (Request.Form.Count > 0) {
+ Logging.Logger.DebugFormat("Posted form follows: \n{0}", ToString(Request.Form));
+ }
+ }
+
+ void Session_Start(object sender, EventArgs e) {
+ // Code that runs when a new session is started
+
+ }
+
+ void Session_End(object sender, EventArgs e) {
+ // Code that runs when a session ends.
+ // Note: The Session_End event is raised only when the sessionstate mode
+ // is set to InProc in the Web.config file. If session mode is set to StateServer
+ // or SQLServer, the event is not raised.
+
+ }
+
+ private static string ToString(NameValueCollection collection) {
+ using (StringWriter sw = new StringWriter()) {
+ foreach (string key in collection.Keys) {
+ sw.WriteLine("{0} = '{1}'", key, collection[key]);
+ }
+ return sw.ToString();
+ }
+ }
+
+ private static string stripQueryString(Uri uri) {
+ UriBuilder builder = new UriBuilder(uri);
+ builder.Query = null;
+ return builder.ToString();
+ }
+
+ </script>
diff --git a/samples/InfoCardRelyingParty/TracePage.aspx b/samples/InfoCardRelyingParty/TracePage.aspx
new file mode 100644
index 0000000..4d6ecc5
--- /dev/null
+++ b/samples/InfoCardRelyingParty/TracePage.aspx
@@ -0,0 +1,18 @@
+<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TracePage.aspx.cs" Inherits="TracePage" %>
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head runat="server">
+ <title></title>
+</head>
+<body>
+ <form id="form1" runat="server">
+ <p align="right">
+ <asp:Button runat="server" Text="Clear log" ID="clearLogButton" OnClick="clearLogButton_Click" />
+ </p>
+ <pre>
+ <asp:PlaceHolder runat="server" ID="placeHolder1" />
+ </pre>
+ </form>
+</body>
+</html>
diff --git a/samples/InfoCardRelyingParty/TracePage.aspx.cs b/samples/InfoCardRelyingParty/TracePage.aspx.cs
new file mode 100644
index 0000000..7075ce3
--- /dev/null
+++ b/samples/InfoCardRelyingParty/TracePage.aspx.cs
@@ -0,0 +1,21 @@
+using System;
+using System.Collections.Generic;
+using System.Web;
+using System.Web.UI;
+using System.Web.UI.WebControls;
+
+/// <summary>
+/// A page to display recent log messages.
+/// </summary>
+public partial class TracePage : System.Web.UI.Page {
+ protected void Page_Load(object sender, EventArgs e) {
+ this.placeHolder1.Controls.Add(new Label { Text = HttpUtility.HtmlEncode(Logging.LogMessages.ToString()) });
+ }
+
+ protected void clearLogButton_Click(object sender, EventArgs e) {
+ Logging.LogMessages.Length = 0;
+
+ // clear the page immediately, and allow for F5 without a Postback warning.
+ Response.Redirect(Request.Url.AbsoluteUri);
+ }
+}
diff --git a/samples/InfoCardRelyingParty/web.config b/samples/InfoCardRelyingParty/web.config
index 76342d6..b3b8654 100644
--- a/samples/InfoCardRelyingParty/web.config
+++ b/samples/InfoCardRelyingParty/web.config
@@ -9,6 +9,7 @@
-->
<configuration>
<configSections>
+ <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler" requirePermission="false" />
<sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
@@ -21,6 +22,25 @@
</sectionGroup>
</sectionGroup>
</configSections>
+
+ <log4net>
+ <appender name="TracePageAppender" type="TracePageAppender, __code">
+ <layout type="log4net.Layout.PatternLayout">
+ <conversionPattern value="%date (GMT%date{%z}) [%thread] %-5level %logger - %message%newline" />
+ </layout>
+ </appender>
+ <!-- Setup the root category, add the appenders and set the default level -->
+ <root>
+ <level value="INFO" />
+ <!--<appender-ref ref="RollingFileAppender" />-->
+ <appender-ref ref="TracePageAppender" />
+ </root>
+ <!-- Specify the level for some specific categories -->
+ <logger name="DotNetOpenAuth">
+ <level value="ALL" />
+ </logger>
+ </log4net>
+
<appSettings/>
<connectionStrings/>
<system.web>
diff --git a/samples/RelyingPartyWebForms/Global.asax.cs b/samples/RelyingPartyWebForms/Global.asax.cs
index fe60707..cdf941b 100644
--- a/samples/RelyingPartyWebForms/Global.asax.cs
+++ b/samples/RelyingPartyWebForms/Global.asax.cs
@@ -33,7 +33,7 @@
protected void Application_BeginRequest(object sender, EventArgs e) {
// System.Diagnostics.Debugger.Launch();
- Logger.DebugFormat("Processing {0} on {1} ", Request.HttpMethod, this.stripQueryString(Request.Url));
+ Logger.DebugFormat("Processing {0} on {1} ", Request.HttpMethod, stripQueryString(Request.Url));
if (Request.QueryString.Count > 0) {
Logger.DebugFormat("Querystring follows: \n{0}", ToString(Request.QueryString));
}
@@ -53,7 +53,7 @@
Logger.ErrorFormat("An unhandled exception was raised. Details follow: {0}", HttpContext.Current.Server.GetLastError());
}
- private string stripQueryString(Uri uri) {
+ private static string stripQueryString(Uri uri) {
UriBuilder builder = new UriBuilder(uri);
builder.Query = null;
return builder.ToString();