0
votes

I am using ASP.NET CORE 2.1 with NLog. I can log to email, files and the internal log without issue.

I would like to send an email once for an http request like a log for that request.

I read that this AspNetBufferingWrapper will work reference https://github.com/NLog/NLog/wiki/AspNetBufferingWrapper-target

Within my nlog.config I have the following target...the aspnetbuffer wrapping my working email target.

<target xsi:type="AspNetBufferingWrapper"
     name="AspNetBufferingWrapper1"
     bufferGrowLimit="Integer"
     growBufferAsNeeded="Boolean"
     bufferSize="Integer">

  <target name="WrappedRulesEngineLogMail" xsi:type="Mail"
        smtpServer="TEST.TEST.COM"
          subject="Wrapped Rules Engine Log"              
        layout="[${longdate}] - [${machinename}] - [${level}] - [${message}] - [${exception:format=toString}]"
        from="[email protected]"
        to="[email protected]"/>      
</target>

The internal log responds with this error message

nlog.config failed. Exception: NLog.NLogConfigurationException: Exception when parsing C:\inetpub\wwwroot\IT\TEST\ACES\Main\Aces.Web\bin\Debug\netcoreapp2.1\nlog.config. ---> System.ArgumentException: Target cannot be found: 'AspNetBufferingWrapper'. Is NLog.Web not included? at NLog.Config.Factory`2.CreateInstance(String name) at NLog.Config.XmlLoggingConfiguration.ParseTargetsElement(NLogXmlElement targetsElement) at NLog.Config.XmlLoggingConfiguration.ParseNLogElement(NLogXmlElement nlogElement, String filePath, Boolean autoReloadDefault) at NLog.Config.XmlLoggingConfiguration.Initialize(XmlReader reader, String fileName, Boolean ignoreErrors)

For completeness I will include my setup within the Program.cs

 public static IWebHost CreateDefaultBuilder(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
            .UseStartup<Startup>()                
            .ConfigureLogging((context, logging) => {
                logging.ClearProviders();                    logging.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace);
                if (context.HostingEnvironment.IsDevelopment())
                {
                    logging.AddDebug();
                }
            })
            .UseNLog()  // NLog: setup NLog for Dependency injection
            .Build();

I have these nuget packages loaded

I do not know how to resolve Target cannot be found: 'AspNetBufferingWrapper'. Is NLog.Web not included? at NLog.Config.Factory`2.CreateInstance(String name)

Why can target be found?

ty

1
I don't know the answer to your question but you should fix the properties of your wrapper, right now they have the type names for the values, rather than the value themselves... For example: growBufferAsNeeded="Boolean" => growBufferAsNeeded="true"pinkfloydx33
Perhaps you need to add a nuget/PackageReference to NLog.Web.AspNetCore: nuget.org/packages/NLog.Web.AspNetCore - it seems like your target and the missing assembly are defined therepinkfloydx33
Yes thanks, I have tried also with setting the properties correctly. Yes NLog.Web.AspNetCore was already included. Still not working. At this moment, I do not feel it is the AspNetBufferingWrapper does not work with asp.net core. I am hoping others have had more success.David
Did you follow the Remarks section in the link you provided? It appears you need to also update the httpModules to include a reference to the assembly. You may be right about it not working in core though. If you read the nuget description on the page I linked earlier, it doesn't mention "targets", just "helpers and layout renderers'. If you read the description of the asp.net version, it explicitly calls out" additional targets". Perhaps this is something to post in the nlog github issues.pinkfloydx33
See also discussion here: github.com/NLog/NLog/issues/2806Rolf Kristensen

1 Answers

0
votes

This is correct. The AspNetBufferingWrapper is in the NLog.Web package and not in the NLog.Web.AspNetCore.

It's not ported to ASP.NET Core (yet) and so it's only supported for ASP.NET non-core.

Link to feature request