Creating A log File for Web Services?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • gregory_may

    #1

    Creating A log File for Web Services?

    Below is a routine I use for creating log files. It works great on most VB
    Applications. However, for web services, it needs some help. The problem
    is I cant reflect properly into a web service to find out where the .DLL is.
    As is, this code writes a log file ok, but the log file ends up buried
    directory deep inside the .Net Framework directories. Anyone know how to
    find the path of a web service .DLL so I can fix this code to write to the
    "bin" directory where the Web Service Dll is?


    Public Function get_name_of_app lication(Option al ByVal
    IncludeFullPath OfExe As Boolean = False) As String
    Dim Application_Dir ectory As String
    Dim Asm As System.Reflecti on.Assembly = _
    System.Reflecti on.Assembly.Get ExecutingAssemb ly

    Dim strConfigLoc As String = Asm.Location
    If Not IncludeFullPath OfExe Then
    strConfigLoc = GetFileNameOnly (Asm.Location)
    End If

    get_name_of_app lication = strConfigLoc.To String
    End Function

    Public Sub COMMON_Module_P rint(ByVal MyMessage As String, Optional ByVal
    WriteToFile As Boolean = False)
    Try
    Static TodaysDate As Date = Now

    Debug.WriteLine (MyMessage)

    If WriteToFile Then
    Dim OutputLogFileNa me As String =
    get_name_of_app lication(True) & ".Log"
    COMMON_FILE_Mod ule.FILE_Append File(MyMessage,
    OutputLogFileNa me)

    If Now.Date < TodaysDate.Date Then
    'Archive OutputFile
    Dim ArchivedFileNam e As String = OutputLogFileNa me &
    ".Archived. " & Now.Date.ToShor tDateString.Rep lace("/", "-")
    FILE_ForceMove( OutputLogFileNa me, ArchivedFileNam e)
    TodaysDate = Now
    End If

    End If

    Catch ex As Exception
    RaiseEvent Mod_Print("COMM ON_Module_Print : " & ex.Message)
    End Try
    End Sub


  • Stephany Young

    #2
    Re: Creating A log File for Web Services?

    This is how I do it:

    Imports System.Web.Serv ices
    Imports System.IO
    Imports System.Xml

    <WebService(Nam espace:="http://<blah.blah>/<blah>")> _
    Public Class <blah>
    Inherits WebService

    Private m_appfolder As String
    Private m_appname As String

    Public Sub New()

    MyBase.New()

    InitializeCompo nent()

    m_appname = Context.Request .ServerVariable s.Item("path_tr anslated")

    m_appfolder = Path.GetDirecto ryName(m_appnam e)

    m_appname = Path.GetFileNam eWithoutExtensi on(m_appname)

    ' Other code here

    End Sub

    ' Other methods here

    End Class

    I then have a stock standard config file in the same directory as the
    <blah>.asmx.v b file that I read using an XML Document object.

    Path.Combine(m_ appfolder, m_appname & ".config") defines that file which
    holds a key/value pair that provides the path for the log file which is
    completed with:

    Path.Combine(Re adConfigSetting ("<blah>", "exceptionfolde r"),
    "Exception.log" )

    This means that the log file is located where you want it.

    There is a gotcha is that whatever account(s) the web service(s) run under
    need to to have write permissions on the folder where you place the log
    file(s).



    "gregory_ma y" <None> wrote in message
    news:OLbwwCoqFH A.332@tk2msftng p13.phx.gbl...[color=blue]
    > Below is a routine I use for creating log files. It works great on most
    > VB Applications. However, for web services, it needs some help. The
    > problem is I cant reflect properly into a web service to find out where
    > the .DLL is. As is, this code writes a log file ok, but the log file ends
    > up buried directory deep inside the .Net Framework directories. Anyone
    > know how to find the path of a web service .DLL so I can fix this code to
    > write to the "bin" directory where the Web Service Dll is?
    >
    >
    > Public Function get_name_of_app lication(Option al ByVal
    > IncludeFullPath OfExe As Boolean = False) As String
    > Dim Application_Dir ectory As String
    > Dim Asm As System.Reflecti on.Assembly = _
    > System.Reflecti on.Assembly.Get ExecutingAssemb ly
    >
    > Dim strConfigLoc As String = Asm.Location
    > If Not IncludeFullPath OfExe Then
    > strConfigLoc = GetFileNameOnly (Asm.Location)
    > End If
    >
    > get_name_of_app lication = strConfigLoc.To String
    > End Function
    >
    > Public Sub COMMON_Module_P rint(ByVal MyMessage As String, Optional
    > ByVal WriteToFile As Boolean = False)
    > Try
    > Static TodaysDate As Date = Now
    >
    > Debug.WriteLine (MyMessage)
    >
    > If WriteToFile Then
    > Dim OutputLogFileNa me As String =
    > get_name_of_app lication(True) & ".Log"
    > COMMON_FILE_Mod ule.FILE_Append File(MyMessage,
    > OutputLogFileNa me)
    >
    > If Now.Date < TodaysDate.Date Then
    > 'Archive OutputFile
    > Dim ArchivedFileNam e As String = OutputLogFileNa me &
    > ".Archived. " & Now.Date.ToShor tDateString.Rep lace("/", "-")
    > FILE_ForceMove( OutputLogFileNa me, ArchivedFileNam e)
    > TodaysDate = Now
    > End If
    >
    > End If
    >
    > Catch ex As Exception
    > RaiseEvent Mod_Print("COMM ON_Module_Print : " & ex.Message)
    > End Try
    > End Sub
    >
    >[/color]


    Comment

    • gregory_may

      #3
      Re: Creating A log File for Web Services?

      I wanted to make it "Automatic" in that I didn't want to hard code anything
      from an XML file. My hope is I can find the path of the "REAL" .dll & put
      the log file there.

      "Stephany Young" <noone@localhos t> wrote in message
      news:%23jmjQ6oq FHA.2876@TK2MSF TNGP12.phx.gbl. ..[color=blue]
      > This is how I do it:
      >
      > Imports System.Web.Serv ices
      > Imports System.IO
      > Imports System.Xml
      >
      > <WebService(Nam espace:="http://<blah.blah>/<blah>")> _
      > Public Class <blah>
      > Inherits WebService
      >
      > Private m_appfolder As String
      > Private m_appname As String
      >
      > Public Sub New()
      >
      > MyBase.New()
      >
      > InitializeCompo nent()
      >
      > m_appname = Context.Request .ServerVariable s.Item("path_tr anslated")
      >
      > m_appfolder = Path.GetDirecto ryName(m_appnam e)
      >
      > m_appname = Path.GetFileNam eWithoutExtensi on(m_appname)
      >
      > ' Other code here
      >
      > End Sub
      >
      > ' Other methods here
      >
      > End Class
      >
      > I then have a stock standard config file in the same directory as the
      > <blah>.asmx.v b file that I read using an XML Document object.
      >
      > Path.Combine(m_ appfolder, m_appname & ".config") defines that file which
      > holds a key/value pair that provides the path for the log file which is
      > completed with:
      >
      > Path.Combine(Re adConfigSetting ("<blah>", "exceptionfolde r"),
      > "Exception.log" )
      >
      > This means that the log file is located where you want it.
      >
      > There is a gotcha is that whatever account(s) the web service(s) run under
      > need to to have write permissions on the folder where you place the log
      > file(s).
      >
      >
      >
      > "gregory_ma y" <None> wrote in message
      > news:OLbwwCoqFH A.332@tk2msftng p13.phx.gbl...[color=green]
      >> Below is a routine I use for creating log files. It works great on most
      >> VB Applications. However, for web services, it needs some help. The
      >> problem is I cant reflect properly into a web service to find out where
      >> the .DLL is. As is, this code writes a log file ok, but the log file ends
      >> up buried directory deep inside the .Net Framework directories. Anyone
      >> know how to find the path of a web service .DLL so I can fix this code to
      >> write to the "bin" directory where the Web Service Dll is?
      >>
      >>
      >> Public Function get_name_of_app lication(Option al ByVal
      >> IncludeFullPath OfExe As Boolean = False) As String
      >> Dim Application_Dir ectory As String
      >> Dim Asm As System.Reflecti on.Assembly = _
      >> System.Reflecti on.Assembly.Get ExecutingAssemb ly
      >>
      >> Dim strConfigLoc As String = Asm.Location
      >> If Not IncludeFullPath OfExe Then
      >> strConfigLoc = GetFileNameOnly (Asm.Location)
      >> End If
      >>
      >> get_name_of_app lication = strConfigLoc.To String
      >> End Function
      >>
      >> Public Sub COMMON_Module_P rint(ByVal MyMessage As String, Optional
      >> ByVal WriteToFile As Boolean = False)
      >> Try
      >> Static TodaysDate As Date = Now
      >>
      >> Debug.WriteLine (MyMessage)
      >>
      >> If WriteToFile Then
      >> Dim OutputLogFileNa me As String =
      >> get_name_of_app lication(True) & ".Log"
      >> COMMON_FILE_Mod ule.FILE_Append File(MyMessage,
      >> OutputLogFileNa me)
      >>
      >> If Now.Date < TodaysDate.Date Then
      >> 'Archive OutputFile
      >> Dim ArchivedFileNam e As String = OutputLogFileNa me &
      >> ".Archived. " & Now.Date.ToShor tDateString.Rep lace("/", "-")
      >> FILE_ForceMove( OutputLogFileNa me, ArchivedFileNam e)
      >> TodaysDate = Now
      >> End If
      >>
      >> End If
      >>
      >> Catch ex As Exception
      >> RaiseEvent Mod_Print("COMM ON_Module_Print : " & ex.Message)
      >> End Try
      >> End Sub
      >>
      >>[/color]
      >
      >[/color]


      Comment

      • Cor Ligthert [MVP]

        #4
        Re: Creating A log File for Web Services?

        Gregory,

        Than why don't you support that name to your function.

        Just my thought,

        Cor


        Comment

        Working...