Author: rgrabowski
Date: Thu Jul 27 20:02:55 2006
New Revision: 426365

URL: http://svn.apache.org/viewvc?rev=426365&view=rev
Log:
Started to implement LOG4NET-87: Support ASP.Net related PatternConverters to 
allow items from the HttpContext.Current.Session, Cache, Request, etc. to be 
captured.

Added:
    logging/log4net/trunk/src/Layout/Pattern/AspNetCachePatternConverter.cs
    logging/log4net/trunk/src/Layout/Pattern/AspNetContextPatternConverter.cs
    logging/log4net/trunk/src/Layout/Pattern/AspNetPatternConverter.cs
    logging/log4net/trunk/src/Layout/Pattern/AspNetRequestPatternConverter.cs
    logging/log4net/trunk/src/Layout/Pattern/AspNetSessionPatternConverter.cs
Modified:
    logging/log4net/trunk/src/Layout/PatternLayout.cs
    logging/log4net/trunk/src/log4net.csproj

Added: logging/log4net/trunk/src/Layout/Pattern/AspNetCachePatternConverter.cs
URL: 
http://svn.apache.org/viewvc/logging/log4net/trunk/src/Layout/Pattern/AspNetCachePatternConverter.cs?rev=426365&view=auto
==============================================================================
--- logging/log4net/trunk/src/Layout/Pattern/AspNetCachePatternConverter.cs 
(added)
+++ logging/log4net/trunk/src/Layout/Pattern/AspNetCachePatternConverter.cs Thu 
Jul 27 20:02:55 2006
@@ -0,0 +1,47 @@
+#region Copyright & License
+//
+// Copyright 2001-2005 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+#endregion
+
+using System.IO;
+using System.Web;
+using log4net.Core;
+using log4net.Util;
+
+namespace log4net.Layout.Pattern
+{
+       internal sealed class AspNetCachePatternConverter : 
PatternLayoutConverter
+       {
+               protected override void Convert(TextWriter writer, LoggingEvent 
loggingEvent)
+               {
+                       if (HttpRuntime.Cache != null)
+                       {
+                               if (Option != null)
+                               {
+                                       WriteObject(writer, 
loggingEvent.Repository, HttpRuntime.Cache[Option]);
+                               }
+                               else
+                               {
+                                       WriteObject(writer, 
loggingEvent.Repository, HttpRuntime.Cache);
+                               }
+                       }
+                       else
+                       {
+                               writer.Write(SystemInfo.NotAvailableText);
+                       }
+               }
+       }
+}
\ No newline at end of file

Added: logging/log4net/trunk/src/Layout/Pattern/AspNetContextPatternConverter.cs
URL: 
http://svn.apache.org/viewvc/logging/log4net/trunk/src/Layout/Pattern/AspNetContextPatternConverter.cs?rev=426365&view=auto
==============================================================================
--- logging/log4net/trunk/src/Layout/Pattern/AspNetContextPatternConverter.cs 
(added)
+++ logging/log4net/trunk/src/Layout/Pattern/AspNetContextPatternConverter.cs 
Thu Jul 27 20:02:55 2006
@@ -0,0 +1,32 @@
+#region Copyright & License
+//
+// Copyright 2001-2005 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+#endregion
+
+using System.IO;
+using System.Web;
+using log4net.Core;
+
+namespace log4net.Layout.Pattern
+{
+       internal sealed class AspNetContextPatternConverter : 
AspNetPatternConverter
+       {
+               protected override void Convert(TextWriter writer, LoggingEvent 
loggingEvent, HttpContext httpContext)
+               {
+                       WriteObject(writer, loggingEvent.Repository, 
httpContext.Items[Option]);
+               }
+       }
+}

Added: logging/log4net/trunk/src/Layout/Pattern/AspNetPatternConverter.cs
URL: 
http://svn.apache.org/viewvc/logging/log4net/trunk/src/Layout/Pattern/AspNetPatternConverter.cs?rev=426365&view=auto
==============================================================================
--- logging/log4net/trunk/src/Layout/Pattern/AspNetPatternConverter.cs (added)
+++ logging/log4net/trunk/src/Layout/Pattern/AspNetPatternConverter.cs Thu Jul 
27 20:02:55 2006
@@ -0,0 +1,58 @@
+#region Copyright & License
+//
+// Copyright 2001-2005 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+#endregion
+
+using System.IO;
+using System.Web;
+using log4net.Core;
+using log4net.Util;
+
+namespace log4net.Layout.Pattern
+{
+       /// <summary>
+       /// Abstract class that provides access to the HttpContext.Current that 
+       /// derived classes need.
+       /// </summary>
+       /// <remarks>
+       /// This class handles the case when HttpContext.Current is null by 
writing
+       /// SystemInfo.NotAvailableText to the writer.
+       /// </remarks>
+       /// <author>Ron Grabowski</author>
+       internal abstract class AspNetPatternConverter : PatternLayoutConverter
+       {
+               protected override void Convert(TextWriter writer, LoggingEvent 
loggingEvent)
+               {
+                       if (HttpContext.Current == null)
+                       {
+                               writer.Write(SystemInfo.NotAvailableText);
+                       }
+                       else
+                       {
+                               Convert(writer, loggingEvent, 
HttpContext.Current);
+                       }
+               }
+
+               /// <summary>
+               /// Derived pattern converters must override this method in 
order to
+               /// convert conversion specifiers in the correct way.
+               /// </summary>
+               /// <param name="writer"><see cref="TextWriter" /> that will 
receive the formatted result.</param>
+               /// <param name="loggingEvent">The <see cref="LoggingEvent" /> 
on which the pattern converter should be executed.</param>
+               /// <param name="httpContext">The <see cref="HttpContext" /> 
under which the ASP.Net request is running.</param>
+               protected abstract void Convert(TextWriter writer, LoggingEvent 
loggingEvent, HttpContext httpContext);
+       }
+}

Added: logging/log4net/trunk/src/Layout/Pattern/AspNetRequestPatternConverter.cs
URL: 
http://svn.apache.org/viewvc/logging/log4net/trunk/src/Layout/Pattern/AspNetRequestPatternConverter.cs?rev=426365&view=auto
==============================================================================
--- logging/log4net/trunk/src/Layout/Pattern/AspNetRequestPatternConverter.cs 
(added)
+++ logging/log4net/trunk/src/Layout/Pattern/AspNetRequestPatternConverter.cs 
Thu Jul 27 20:02:55 2006
@@ -0,0 +1,47 @@
+#region Copyright & License
+//
+// Copyright 2001-2005 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+#endregion
+
+using System.IO;
+using System.Web;
+using log4net.Core;
+using log4net.Util;
+
+namespace log4net.Layout.Pattern
+{
+       internal sealed class AspNetRequestPatternConverter : 
AspNetPatternConverter
+       {
+               protected override void Convert(TextWriter writer, LoggingEvent 
loggingEvent, HttpContext httpContext)
+               {
+                       if (httpContext.Request != null)
+                       {
+                               if (Option != null)
+                               {
+                                       WriteObject(writer, 
loggingEvent.Repository, httpContext.Request[Option]);
+                               }
+                               else
+                               {
+                                       WriteObject(writer, 
loggingEvent.Repository, httpContext.Request);
+                               }
+                       }
+                       else
+                       {
+                               writer.Write(SystemInfo.NotAvailableText);
+                       }
+               }
+       }
+}

Added: logging/log4net/trunk/src/Layout/Pattern/AspNetSessionPatternConverter.cs
URL: 
http://svn.apache.org/viewvc/logging/log4net/trunk/src/Layout/Pattern/AspNetSessionPatternConverter.cs?rev=426365&view=auto
==============================================================================
--- logging/log4net/trunk/src/Layout/Pattern/AspNetSessionPatternConverter.cs 
(added)
+++ logging/log4net/trunk/src/Layout/Pattern/AspNetSessionPatternConverter.cs 
Thu Jul 27 20:02:55 2006
@@ -0,0 +1,47 @@
+#region Copyright & License
+//
+// Copyright 2001-2006 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+#endregion
+
+using System.IO;
+using System.Web;
+using log4net.Core;
+using log4net.Util;
+
+namespace log4net.Layout.Pattern
+{
+       internal sealed class AspNetSessionPatternConverter : 
AspNetPatternConverter
+       {
+               protected override void Convert(TextWriter writer, LoggingEvent 
loggingEvent, HttpContext httpContext)
+               {
+                       if (httpContext.Session != null)
+                       {
+                               if (Option != null)
+                               {
+                                       WriteObject(writer, 
loggingEvent.Repository, httpContext.Session[Option]);
+                               }
+                               else
+                               {
+                                       WriteObject(writer, 
loggingEvent.Repository, httpContext.Session);
+                               }
+                       }
+                       else
+                       {
+                               writer.Write(SystemInfo.NotAvailableText);
+                       }
+               }
+       }
+}
\ No newline at end of file

Modified: logging/log4net/trunk/src/Layout/PatternLayout.cs
URL: 
http://svn.apache.org/viewvc/logging/log4net/trunk/src/Layout/PatternLayout.cs?rev=426365&r1=426364&r2=426365&view=diff
==============================================================================
--- logging/log4net/trunk/src/Layout/PatternLayout.cs (original)
+++ logging/log4net/trunk/src/Layout/PatternLayout.cs Thu Jul 27 20:02:55 2006
@@ -23,6 +23,13 @@
 using log4net.Core;
 using log4net.Layout.Pattern;
 using log4net.Util;
+using log4net.Util.PatternStringConverters;
+using 
AppDomainPatternConverter=log4net.Layout.Pattern.AppDomainPatternConverter;
+using DatePatternConverter=log4net.Layout.Pattern.DatePatternConverter;
+using IdentityPatternConverter=log4net.Layout.Pattern.IdentityPatternConverter;
+using PropertyPatternConverter=log4net.Layout.Pattern.PropertyPatternConverter;
+using UserNamePatternConverter=log4net.Layout.Pattern.UserNamePatternConverter;
+using UtcDatePatternConverter=log4net.Layout.Pattern.UtcDatePatternConverter;
 
 namespace log4net.Layout
 {
@@ -767,9 +774,13 @@
                {
                        s_globalRulesRegistry = new Hashtable(45);
 
-                       s_globalRulesRegistry.Add("literal", 
typeof(log4net.Util.PatternStringConverters.LiteralPatternConverter));
-                       s_globalRulesRegistry.Add("newline", 
typeof(log4net.Util.PatternStringConverters.NewLinePatternConverter));
-                       s_globalRulesRegistry.Add("n", 
typeof(log4net.Util.PatternStringConverters.NewLinePatternConverter));
+                       s_globalRulesRegistry.Add("literal", 
typeof(LiteralPatternConverter));
+                       s_globalRulesRegistry.Add("newline", 
typeof(NewLinePatternConverter));
+                       s_globalRulesRegistry.Add("n", 
typeof(NewLinePatternConverter));
+
+                       s_globalRulesRegistry.Add("aspnet-cache", 
typeof(AspNetCachePatternConverter));
+                       s_globalRulesRegistry.Add("aspnet-context", 
typeof(AspNetContextPatternConverter));
+                       s_globalRulesRegistry.Add("aspnet-request", 
typeof(AspNetRequestPatternConverter));
 
                        s_globalRulesRegistry.Add("c", 
typeof(LoggerPatternConverter));
                        s_globalRulesRegistry.Add("logger", 
typeof(LoggerPatternConverter));
@@ -811,11 +822,11 @@
                        s_globalRulesRegistry.Add("t", 
typeof(ThreadPatternConverter));
                        s_globalRulesRegistry.Add("thread", 
typeof(ThreadPatternConverter));
 
-                       // For backwards compatibility the NDC patters
+                       // For backwards compatibility the NDC patterns
                        s_globalRulesRegistry.Add("x", 
typeof(NdcPatternConverter));
                        s_globalRulesRegistry.Add("ndc", 
typeof(NdcPatternConverter));
 
-                       // For backwards compatibility the MDC patters just do 
a property lookup
+                       // For backwards compatibility the MDC patterns just do 
a property lookup
                        s_globalRulesRegistry.Add("X", 
typeof(PropertyPatternConverter));
                        s_globalRulesRegistry.Add("mdc", 
typeof(PropertyPatternConverter));
 

Modified: logging/log4net/trunk/src/log4net.csproj
URL: 
http://svn.apache.org/viewvc/logging/log4net/trunk/src/log4net.csproj?rev=426365&r1=426364&r2=426365&view=diff
==============================================================================
--- logging/log4net/trunk/src/log4net.csproj (original)
+++ logging/log4net/trunk/src/log4net.csproj Thu Jul 27 20:02:55 2006
@@ -602,6 +602,31 @@
                     SubType = "Code"
                     BuildAction = "Compile"
                 />
+               <File
+                    RelPath = "Layout\Pattern\AspNetCachePatternConverter.cs"
+                    SubType = "Code"
+                    BuildAction = "Compile"
+                />
+                <File
+                    RelPath = "Layout\Pattern\AspNetContextPatternConverter.cs"
+                    SubType = "Code"
+                    BuildAction = "Compile"
+                />
+                <File
+                    RelPath = "Layout\Pattern\AspNetPatternConverter.cs"
+                    SubType = "Code"
+                    BuildAction = "Compile"
+                />
+                <File
+                    RelPath = "Layout\Pattern\AspNetRequestPatternConverter.cs"
+                    SubType = "Code"
+                    BuildAction = "Compile"
+                />
+                <File
+                    RelPath = "Layout\Pattern\AspNetSessionPatternConverter.cs"
+                    SubType = "Code"
+                    BuildAction = "Compile"
+                />
                 <File
                     RelPath = "Layout\Pattern\DatePatternConverter.cs"
                     SubType = "Code"


Reply via email to