-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from Xharze/MoveStuffFromExtended
Move stuff from extended
- Loading branch information
Showing
12 changed files
with
686 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
NLog.Web/LayoutRenderers/AspNetApplicationValueLayoutRenderer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
using System; | ||
using System.Globalization; | ||
using System.Text; | ||
using System.Web; | ||
using NLog.Config; | ||
using NLog.LayoutRenderers; | ||
|
||
namespace NLog.Web.LayoutRenderers | ||
{ | ||
/// <summary> | ||
/// ASP.NET Application variable. | ||
/// </summary> | ||
/// <remarks> | ||
/// Use this layout renderer to insert the value of the specified variable stored | ||
/// in the ASP.NET Application dictionary. | ||
/// </remarks> | ||
/// <example> | ||
/// <para>You can set the value of an ASP.NET Application variable by using the following code:</para> | ||
/// <code lang="C#"> | ||
/// <![CDATA[ | ||
/// HttpContext.Current.Application["myvariable"] = 123; | ||
/// HttpContext.Current.Application["stringvariable"] = "aaa BBB"; | ||
/// HttpContext.Current.Application["anothervariable"] = DateTime.Now; | ||
/// ]]> | ||
/// </code> | ||
/// <para>Example usage of ${aspnet-application}:</para> | ||
/// <code lang="NLog Layout Renderer"> | ||
/// ${aspnet-application:variable=myvariable} - produces "123" | ||
/// ${aspnet-application:variable=anothervariable} - produces "01/01/2006 00:00:00" | ||
/// ${aspnet-application:variable=anothervariable:culture=pl-PL} - produces "2006-01-01 00:00:00" | ||
/// ${aspnet-application:variable=myvariable:padding=5} - produces " 123" | ||
/// ${aspnet-application:variable=myvariable:padding=-5} - produces "123 " | ||
/// ${aspnet-application:variable=stringvariable:upperCase=true} - produces "AAA BBB" | ||
/// </code> | ||
/// </example> | ||
[LayoutRenderer("aspnet-application")] | ||
public class AspNetApplicationValueLayoutRenderer : LayoutRenderer | ||
{ | ||
/// <summary> | ||
/// Gets or sets the variable name. | ||
/// </summary> | ||
/// <docgen category='Rendering Options' order='10' /> | ||
[RequiredParameter] | ||
[DefaultParameter] | ||
public string Variable { get; set; } | ||
|
||
/// <summary> | ||
/// Renders the specified ASP.NET Application variable and appends it to the specified <see cref="StringBuilder" />. | ||
/// </summary> | ||
/// <param name="builder">The <see cref="StringBuilder"/> to append the rendered data to.</param> | ||
/// <param name="logEvent">Logging event.</param> | ||
protected override void Append(StringBuilder builder, LogEventInfo logEvent) | ||
{ | ||
if (this.Variable == null) | ||
{ | ||
return; | ||
} | ||
|
||
HttpContext context = HttpContext.Current; | ||
if (context == null) | ||
{ | ||
return; | ||
} | ||
|
||
if (context.Application == null) | ||
{ | ||
return; | ||
} | ||
|
||
builder.Append(Convert.ToString(context.Application[this.Variable], CultureInfo.InvariantCulture)); | ||
} | ||
} | ||
} |
104 changes: 104 additions & 0 deletions
104
NLog.Web/LayoutRenderers/AspNetRequestValueLayoutRenderer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
using System.Text; | ||
using System.Web; | ||
using NLog.Config; | ||
using NLog.LayoutRenderers; | ||
|
||
namespace NLog.Web.LayoutRenderers | ||
{ | ||
/// <summary> | ||
/// ASP.NET Request variable. | ||
/// </summary> | ||
/// <remarks> | ||
/// Use this layout renderer to insert the value of the specified parameter of the | ||
/// ASP.NET Request object. | ||
/// </remarks> | ||
/// <example> | ||
/// <para>Example usage of ${aspnet-request}:</para> | ||
/// <code lang="NLog Layout Renderer"> | ||
/// ${aspnet-request:item=v} | ||
/// ${aspnet-request:querystring=v} | ||
/// ${aspnet-request:form=v} | ||
/// ${aspnet-request:cookie=v} | ||
/// ${aspnet-request:serverVariable=v} | ||
/// </code> | ||
/// </example> | ||
[LayoutRenderer("aspnet-request")] | ||
public class AspNetRequestValueLayoutRenderer : LayoutRenderer | ||
{ | ||
/// <summary> | ||
/// Gets or sets the item name. The QueryString, Form, Cookies, or ServerVariables collection variables having the specified name are rendered. | ||
/// </summary> | ||
/// <docgen category='Rendering Options' order='10' /> | ||
[DefaultParameter] | ||
public string Item { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the QueryString variable to be rendered. | ||
/// </summary> | ||
/// <docgen category='Rendering Options' order='10' /> | ||
public string QueryString { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the form variable to be rendered. | ||
/// </summary> | ||
/// <docgen category='Rendering Options' order='10' /> | ||
public string Form { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the cookie to be rendered. | ||
/// </summary> | ||
/// <docgen category='Rendering Options' order='10' /> | ||
public string Cookie { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the ServerVariables item to be rendered. | ||
/// </summary> | ||
/// <docgen category='Rendering Options' order='10' /> | ||
public string ServerVariable { get; set; } | ||
|
||
/// <summary> | ||
/// Renders the specified ASP.NET Request variable and appends it to the specified <see cref="StringBuilder" />. | ||
/// </summary> | ||
/// <param name="builder">The <see cref="StringBuilder"/> to append the rendered data to.</param> | ||
/// <param name="logEvent">Logging event.</param> | ||
protected override void Append(StringBuilder builder, LogEventInfo logEvent) | ||
{ | ||
HttpContext context = HttpContext.Current; | ||
if (context == null) | ||
{ | ||
return; | ||
} | ||
|
||
if (context.Request == null) | ||
{ | ||
return; | ||
} | ||
|
||
if (this.QueryString != null) | ||
{ | ||
builder.Append(context.Request.QueryString[this.QueryString]); | ||
} | ||
else if (this.Form != null) | ||
{ | ||
builder.Append(context.Request.Form[this.Form]); | ||
} | ||
else if (this.Cookie != null) | ||
{ | ||
HttpCookie cookie = context.Request.Cookies[this.Cookie]; | ||
|
||
if (cookie != null) | ||
{ | ||
builder.Append(cookie.Value); | ||
} | ||
} | ||
else if (this.ServerVariable != null) | ||
{ | ||
builder.Append(context.Request.ServerVariables[this.ServerVariable]); | ||
} | ||
else if (this.Item != null) | ||
{ | ||
builder.Append(context.Request[this.Item]); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System.Text; | ||
using System.Web; | ||
using NLog.LayoutRenderers; | ||
|
||
namespace NLog.Web.LayoutRenderers | ||
{ | ||
/// <summary> | ||
/// ASP.NET Session ID. | ||
/// </summary> | ||
[LayoutRenderer("aspnet-sessionid")] | ||
public class AspNetSessionIDLayoutRenderer : LayoutRenderer | ||
{ | ||
/// <summary> | ||
/// Renders the ASP.NET Session ID appends it to the specified <see cref="StringBuilder" />. | ||
/// </summary> | ||
/// <param name="builder">The <see cref="StringBuilder"/> to append the rendered data to.</param> | ||
/// <param name="logEvent">Logging event.</param> | ||
protected override void Append(StringBuilder builder, LogEventInfo logEvent) | ||
{ | ||
HttpContext context = HttpContext.Current; | ||
if (context == null) | ||
{ | ||
return; | ||
} | ||
|
||
if (context.Session == null) | ||
{ | ||
return; | ||
} | ||
|
||
builder.Append(context.Session.SessionID); | ||
} | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
NLog.Web/LayoutRenderers/AspNetSessionValueLayoutRenderer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
using System; | ||
using System.Globalization; | ||
using System.Text; | ||
using System.Web; | ||
using NLog.Config; | ||
using NLog.LayoutRenderers; | ||
|
||
namespace NLog.Web.LayoutRenderers | ||
{ | ||
/// <summary> | ||
/// ASP.NET Session variable. | ||
/// </summary> | ||
/// <remarks> | ||
/// Use this layout renderer to insert the value of the specified variable stored | ||
/// in the ASP.NET Session dictionary. | ||
/// </remarks> | ||
/// <example> | ||
/// <para>You can set the value of an ASP.NET Session variable by using the following code:</para> | ||
/// <code lang="C#"> | ||
/// <![CDATA[ | ||
/// HttpContext.Current.Session["myvariable"] = 123; | ||
/// HttpContext.Current.Session["stringvariable"] = "aaa BBB"; | ||
/// HttpContext.Current.Session["anothervariable"] = DateTime.Now; | ||
/// ]]> | ||
/// </code> | ||
/// <para>Example usage of ${aspnet-session}:</para> | ||
/// <code lang="NLog Layout Renderer"> | ||
/// ${aspnet-session:variable=myvariable} - produces "123" | ||
/// ${aspnet-session:variable=anothervariable} - produces "01/01/2006 00:00:00" | ||
/// ${aspnet-session:variable=anothervariable:culture=pl-PL} - produces "2006-01-01 00:00:00" | ||
/// ${aspnet-session:variable=myvariable:padding=5} - produces " 123" | ||
/// ${aspnet-session:variable=myvariable:padding=-5} - produces "123 " | ||
/// ${aspnet-session:variable=stringvariable:upperCase=true} - produces "AAA BBB" | ||
/// </code> | ||
/// </example> | ||
[LayoutRenderer("aspnet-session")] | ||
public class AspNetSessionValueLayoutRenderer : LayoutRenderer | ||
{ | ||
/// <summary> | ||
/// Gets or sets the session variable name. | ||
/// </summary> | ||
/// <docgen category='Rendering Options' order='10' /> | ||
[DefaultParameter] | ||
public string Variable { get; set; } | ||
|
||
/// <summary> | ||
/// Renders the specified ASP.NET Session value and appends it to the specified <see cref="StringBuilder" />. | ||
/// </summary> | ||
/// <param name="builder">The <see cref="StringBuilder"/> to append the rendered data to.</param> | ||
/// <param name="logEvent">Logging event.</param> | ||
protected override void Append(StringBuilder builder, LogEventInfo logEvent) | ||
{ | ||
if (this.Variable == null) | ||
{ | ||
return; | ||
} | ||
|
||
HttpContext context = HttpContext.Current; | ||
if (context == null) | ||
{ | ||
return; | ||
} | ||
|
||
if (context.Session == null) | ||
{ | ||
return; | ||
} | ||
|
||
builder.Append(Convert.ToString(context.Session[this.Variable], CultureInfo.InvariantCulture)); | ||
} | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
NLog.Web/LayoutRenderers/AspNetUserAuthTypeLayoutRenderer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System.Text; | ||
using System.Web; | ||
using NLog.LayoutRenderers; | ||
|
||
namespace NLog.Web.LayoutRenderers | ||
{ | ||
/// <summary> | ||
/// ASP.NET User variable. | ||
/// </summary> | ||
[LayoutRenderer("aspnet-user-authtype")] | ||
public class AspNetUserAuthTypeLayoutRenderer : LayoutRenderer | ||
{ | ||
/// <summary> | ||
/// Renders the specified ASP.NET User.Identity.AuthenticationType variable and appends it to the specified <see cref="StringBuilder" />. | ||
/// </summary> | ||
/// <param name="builder">The <see cref="StringBuilder"/> to append the rendered data to.</param> | ||
/// <param name="logEvent">Logging event.</param> | ||
protected override void Append(StringBuilder builder, LogEventInfo logEvent) | ||
{ | ||
HttpContext context = HttpContext.Current; | ||
if (context == null) | ||
{ | ||
return; | ||
} | ||
|
||
if (context.User == null) | ||
{ | ||
return; | ||
} | ||
|
||
if (context.User.Identity == null) | ||
{ | ||
return; | ||
} | ||
|
||
if (!context.User.Identity.IsAuthenticated) | ||
{ | ||
return; | ||
} | ||
|
||
builder.Append(context.User.Identity.AuthenticationType); | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
NLog.Web/LayoutRenderers/AspNetUserIdentityLayoutRenderer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System.Text; | ||
using System.Web; | ||
using NLog.LayoutRenderers; | ||
|
||
namespace NLog.Web.LayoutRenderers | ||
{ | ||
/// <summary> | ||
/// ASP.NET User variable. | ||
/// </summary> | ||
[LayoutRenderer("aspnet-user-identity")] | ||
public class AspNetUserIdentityLayoutRenderer : LayoutRenderer | ||
{ | ||
/// <summary> | ||
/// Renders the specified ASP.NET User.Identity.Name variable and appends it to the specified <see cref="StringBuilder" />. | ||
/// </summary> | ||
/// <param name="builder">The <see cref="StringBuilder"/> to append the rendered data to.</param> | ||
/// <param name="logEvent">Logging event.</param> | ||
protected override void Append(StringBuilder builder, LogEventInfo logEvent) | ||
{ | ||
var context = HttpContext.Current; | ||
if (context == null) | ||
{ | ||
return; | ||
} | ||
|
||
if (context.User == null) | ||
{ | ||
return; | ||
} | ||
|
||
if (context.User.Identity == null) | ||
{ | ||
return; | ||
} | ||
|
||
builder.Append(context.User.Identity.Name); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.