-
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.
LogManager.Setup() - Added support for RegisterNLogWeb + RegisterAspN…
…etLayoutRenderer
- Loading branch information
Showing
7 changed files
with
118 additions
and
9 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
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
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
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,23 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using NLog.Config; | ||
|
||
namespace NLog.Web | ||
{ | ||
/// <summary> | ||
/// Extension methods to setup LogFactory options | ||
/// </summary> | ||
public static class SetupBuilderExtensions | ||
{ | ||
/// <summary> | ||
/// Register the NLog.Web LayoutRenderers before loading NLog config | ||
/// </summary> | ||
public static ISetupBuilder RegisterNLogWeb(this ISetupBuilder setupBuilder) | ||
{ | ||
setupBuilder.SetupExtensions(e => e.RegisterNLogWeb()); | ||
return setupBuilder; | ||
} | ||
} | ||
} |
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,33 @@ | ||
using System; | ||
using System.Web; | ||
using NLog.Config; | ||
using NLog.Web.LayoutRenderers; | ||
|
||
namespace NLog.Web | ||
{ | ||
/// <summary> | ||
/// Extension methods to setup NLog extensions, so they are known when loading NLog LoggingConfiguration | ||
/// </summary> | ||
public static class SetupExtensionsBuilderExtensions | ||
{ | ||
/// <summary> | ||
/// Register the NLog.Web LayoutRenderers | ||
/// </summary> | ||
public static ISetupExtensionsBuilder RegisterNLogWeb(this ISetupExtensionsBuilder setupBuilder) | ||
{ | ||
return setupBuilder.RegisterAssembly(typeof(SetupExtensionsBuilderExtensions).Assembly); | ||
} | ||
|
||
/// <summary> | ||
/// Register a custom layout renderer using custom delegate-method <paramref name="layoutMethod" /> | ||
/// </summary> | ||
/// <param name="setupBuilder">Fluent style</param> | ||
/// <param name="name">Name of the layout renderer - without ${}.</param> | ||
/// <param name="layoutMethod">Delegate method that returns layout renderer output.</param> | ||
public static ISetupExtensionsBuilder RegisterAspNetLayoutRenderer(this ISetupExtensionsBuilder setupBuilder, string name, Func<LogEventInfo, HttpContextBase, LoggingConfiguration, object> layoutMethod) | ||
{ | ||
AspNetLayoutRendererBase.Register(name, layoutMethod); | ||
return setupBuilder; | ||
} | ||
} | ||
} |
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,29 @@ | ||
using System; | ||
using NLog.Web.Targets.Wrappers; | ||
using Xunit; | ||
|
||
namespace NLog.Web.Tests | ||
{ | ||
public sealed class AspNetTests | ||
{ | ||
[Fact] | ||
public void RegisterNLogWebTest() | ||
{ | ||
// Act | ||
var logFactory = new NLog.LogFactory().Setup().RegisterNLogWeb().LoadConfigurationFromXml( | ||
@"<nlog throwConfigExceptions='true'> | ||
<targets> | ||
<target type='AspNetBufferingWrapper' name='hello'> | ||
<target type='Memory' name='hello_wrapped' /> | ||
</target> | ||
</targets> | ||
<rules> | ||
<logger name='*' writeTo='hello' /> | ||
</rules> | ||
</nlog>").LogFactory; | ||
|
||
// Assert | ||
Assert.NotNull(logFactory?.Configuration?.FindTargetByName<AspNetBufferingTargetWrapper>("hello")); | ||
} | ||
} | ||
} |
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