Logging Will Not Work

Discussion in 'ASP.NET / ASP.NET Core' started by blugold19, Feb 9, 2010.

  1. Hello,

    I am attempting to write to log files on my site with no success. My code is as follows:

    LogPath = System.Web.HttpContext.Current.Server.MapPath("~/faresharkbe/App_Data/Logs/" & GetLogPath(LogType))

    Dim objStreamWriter As StreamWriter
    Try
    objStreamWriter = File.AppendText(LogPath)
    objStreamWriter.WriteLine(System.DateTime.Now & " " & "test")
    Catch ex As Exception
    Finally
    If Not objStreamWriter Is Nothing Then
    objStreamWriter.Close()
    End If
    End Try

    Doing some debugging, the logpath variable is: E:\web\faresharkbe\htdocs\faresharkbe\App_Data\Logs\Daemon\log.txt This is the correct server path according to DASP support.

    This code does work on my local server. If I go to the app_data\logs\daemon directory for my site, however, there is never a log file there.

    Can anyone help?
     
  2. Figured it out

    I found another post and reailzed it is the App_Data directory that is causing the permissions issue. I created a "logs" directory and wrote the logs to this location and things seem to work now. So the syntax to get to this directory is:

    Server.MapPath("~/Logs/yourtempfile.txt")
     
  3. Ramses

    Ramses Guest

    Thanks for posting the solution. The App_data cannot be really access by applications for security reasons I believe.
     

Share This Page