Unable to implement JSNLog on .NET 4.5 MVC application

守給你的承諾、 提交于 2019-12-20 03:31:02

问题


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:

  1. JSN Log v-2.27.1
  2. JSNLog.Log4Net v-2.27.1
  3. 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:

  1. Created a MVC application from VS 2017.
  2. Installed log4net and added server side logging.(This is working fine)
  3. Downloaded JSNLog & JSNLog.Log4Net
  4. JSNLog Configurations are added in Web.Config automatically.
  5. Added @Html.Raw(JSNLog.JavascriptLogging.Configure()) in the view. (This is working for .NET 4.6.1 only).
  6. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!