Skip to content

rongfengliang/NLog.Web

 
 

Repository files navigation

NLog.Web (ASP.NET 4 + 5 + CoreCLR)

ASP.NET 4: Version

ASP.NET 5: Version

AppVeyor codecov.io

This package is an extension to NLog.

This package contains targets and layout-renderes specific to ASP.Net and IIS.

ASP.NET 5

There is a special package for ASP.NET 5 / MVC 6. This is needed because HttpContext.Current isn't available in ASP.NET 5 and we can't detect if ASP.NET 4 or 5 is used.

The following parts are supported in ASP.NET 5:

  • aspnet-item
  • aspnet-request (except ServerVariable)
  • aspnet-session
  • aspnet-user-authtype
  • aspnet-user-identity
  • iis-site-name

Please note:

Usage

In your nlog.config:

  <extensions>
    <!--enable NLog.Web for ASP.NET5-->
    <add assembly="NLog.Web.ASPNET5"/>
  </extensions>

In your startup.cs

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            //add NLog to aspnet5
            loggerFactory.AddNLog();

            //add NLog.Web (only needed if NLog.Web.ASPNET5 is needed)
            app.AddNLogWeb();

            //configure nlog.config in your project root
            env.ConfigureNLog("nlog.config");

in project.json:

    "dependencies": {
        "NLog.Extensions.Logging": "1.0.0-rc1-final-2016-03-11",
        "NLog.Web.ASPNET5": "4.2.2"
    },

Content

This package contains one target, one target-wrapper, multiple layout renderers and one httpmodule.

Targets

  • AspNetTrace
  • AspNetBufferingWrapper

See Target documentation at the NLog wiki

Layout renderers

See Layout renderers documentation at the NLog wiki

Configuration

For the targets and layout renderers, no additional configuration is needed.

The NLogHttpModule needs a registration in the web.config:

<system.webServer> 
	<modules runAllManagedModulesForAllRequests="true"> 
		<add name="NLog" type="NLog.Web.NLogHttpModule, NLog.Web" />
	</modules>
</system.webServer>

License

BSD

About

NLog targets specific for Web

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 98.8%
  • Batchfile 1.2%