Asp – Could someone give me a “hello world” example of logging in ASP.NET


I'm trying to get a bare-bones example of logging going in my ASP.NET application. I would like to use the My.Log functionality to write out error log messages to a text log file. I have tried several things via 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 basic question is: What do I need in my web.config file (and/or anywhere else, if necessary) so that I can write messages with


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


Edit: specific code used:

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

Then in the code:

My.Log.DefaultFileLogWriter.CustomLocation = "D:\"
My.Log.DefaultFileLogWriter.BaseFileName = "log"

(this would write to D:\log.log).

Related Question