asp.net - Using NLog with asp-net layout renderers in AspNet vNext (MVC 6) -
i trying integrate nlog in aspnet 5 (or using new name aspnet core 1.0) web app. not sure if possible @ want log logged in user. nlog config file.
<?xml version="1.0" encoding="utf-8" ?> <nlog xmlns="http://www.nlog-project.org/schemas/nlog.xsd" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" autoreload="true"> <targets> <target name="logfile" xsi:type="file" filename="file.txt" layout="${longdate}|${message}|${identity}|${aspnet-user-identity}" /> </targets> <rules> <logger name="webapplication2.*" minlevel="info" writeto="logfile" /> </rules> </nlog>
the thing
system.argumentexception: layoutrenderer cannot found: 'aspnet-user-identity'
my project.json file looks like:
"dependencies": { ..... "nlog.framework.logging": "1.0.0-rc1-final", "nlog": "4.4.0-alpha1", "nlog.config": "4.3.0-beta1", "nlog.extended": "4.0.0-rc", "nlog.web": "4.1.0" },
maybe missing something, or not yet supported nlog ?
edit: found out auto load of extensions not supported. so, have modify nlog.config like:
<extensions> <add assembly="nlog.web"/> <add assembly="nlog.extended"/> </extensions>
but blank input current user. ideas ?
the internal log give more info why loading extension failed.
there other ways load extensions, assemblyfile attribute , programmatically:
//target configurationitemfactory.default.targets .registerdefinition("myfirst", typeof(mynamespace.myfirsttarget)); //layout renderer configurationitemfactory.default.layoutrenderers .registerdefinition("hello-world", typeof(mynamespace.helloworldlayoutrenderer ));
edit: did tests. works in loading assembly:
<extensions> <add assembly="nlog.web" /> </extensions>
but bad nlog.web isn't asp.net 5 compatible, yet. can't use httpcontext.current
there.
edit: asp.net 5 compatible version of nlog.web available! see nuget
Comments
Post a Comment