Can someone give me an example of “hello world” registration in ASP.NET?

I am trying to get an example of bare-bones registration in my ASP.NET application. I would like to use the My.Log function to write error log messages to a text log file. I tried a few things through Google, but none of them seem to work. In general, when I use any of the properties of My.Log.DefaultFileWriter in the code, it says: "Object reference not set."

My main question is: what do I need in my web.config file (and / or somewhere else, if necessary) so that I can write messages using

My.Log.WriteEntry("blahblahblah")

in my code, in a text file, D: \ log.txt?

Thank.


Edit: uses a special code:

    <system.diagnostics>
    <sources >
      <source name="DefaultSource" switchName="DefaultSwitch">
        <listeners>
          <add name="FileLog"/>
        </listeners>
      </source>
    </sources>
    <sharedListeners>    
      <add name="FileLog" 
           type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"    
           initializeData="FileLogWriter" />
    </sharedListeners>
    <switches>
      <add name="DefaultSwitch" value="Verbose"/>
    </switches>
    <trace autoflush="true"></trace>
  </system.diagnostics>

Then in the code:

My.Log.DefaultFileLogWriter.CustomLocation = "D:\"
My.Log.DefaultFileLogWriter.BaseFileName = "log"
My.Log.WriteEntry("blahblahblah")

(this is written to D: \ log.log).

+3
source share
3
+4
+2

log4net is a bst option to log into asp.net

0
source

Source: https://habr.com/ru/post/1698830/


All Articles