问题
Issue: I am trying to use JSNLog in MVC application(Target Framework: .NET 4.5). I am getting "JSN Log does not exist in the current context" error.
I tried installing JSNLog 2.28.0, but it was showing:
Could not install package 'JSNLog 2.28.0'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.5', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.
So, I have installed these following packages for logging:
- JSN Log v-2.27.1
- JSNLog.Log4Net v-2.27.1
- log4Net v-2.0.8
This same thing i have done earlier on .NET Framework 4.6.1 and in that time it worked very easily. Is there something i am missing?
My Steps are:
- Created a MVC application from VS 2017.
- Installed log4net and added server side logging.(This is working fine)
- Downloaded JSNLog & JSNLog.Log4Net
- JSNLog Configurations are added in Web.Config automatically.
- Added @Html.Raw(JSNLog.JavascriptLogging.Configure()) in the view. (This is working for .NET 4.6.1 only).
- Added my own script for JSN Log.
My Sample code is given below:
I am getting this below error on Index.cshtml page:
Here is my JSNLog configuration in Web.Config:
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
<section name="jsnlog" type="JSNLog.ConfigurationSectionHandler, JSNLog" requirePermission="false" /><sectionGroup name="common">
<section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
</sectionGroup>
</configSections>
<log4net>
<appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
<!-- prevent log4net from locking the file, otherwise integration tests cannot remove it for each test-->
<param name="LockingModel" type="log4net.Appender.FileAppender+MinimalLock" />
<file value="Logs\log.txt" />
<appendToFile value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%utcdate | %level | %logger | %message%newline" />
</layout>
</appender>
<root>
<level value="TRACE" />
<appender-ref ref="RollingFile" />
</root>
</log4net>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
<httpHandlers>
<add verb="*" path="*.logger" type="JSNLog.LoggerHandler, JSNLog" />
</httpHandlers>
</system.web>
<jsnlog productionLibraryPath="~/Scripts/jsnlog.min.js">
</jsnlog><common>
<logging>
<factoryAdapter type="Common.Logging.Log4Net.Universal.Log4NetFactoryAdapter, Common.Logging.Log4Net.Universal" />
</logging>
</common>
I tried using jsnlog dll from .NET 4.6.1 project.
Here that previous error was gone, but it is giving this error now: POST http://localhost:xxxxx/jsnlog.logger 500 (Internal Server Error)
Screenshot:
来源:https://stackoverflow.com/questions/51982482/unable-to-implement-jsnlog-on-net-4-5-mvc-application