473,785 Members | 2,480 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
Nov 21 '05 #1
3 4901
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:OL******** *****@tk2msftng p13.phx.gbl...
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

Nov 21 '05 #2
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:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
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:OL******** *****@tk2msftng p13.phx.gbl...
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


Nov 21 '05 #3
Gregory,

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

Just my thought,

Cor
Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1157
by: tim.tadh | last post by:
Hi I am writing a program that allows a user to annotate text documents, and later html, html variants, and PDF files. My program is able to load multiple documents at once and creat linked anotations between these documents. Therefore i want to create a custom system to save the files. Ideally I want a project description file that gives the program all the neccessary information to build the project when loaded, the document files,...
7
7515
by: Jan Danielsson | last post by:
Hello all, Is there any way to create a file with a specified size?
7
3953
by: Selden McCabe | last post by:
I'm using the following code to write some text to a file: objWriter = New StreamWriter(FullPath, True, System.Text.Encoding.ASCII) For nRow = 1 To sData.Length - 1 objWriter.WriteLine(sData(nRow)) Next nRow objWriter.Flush() objWriter.Close() When I run this in the IDE, it works. When I compile it and run the EXE, it
0
1204
by: reidarT | last post by:
Ugyldig på toppnivået av dokumentet. Feil under behandling av ressursen file:///C:/VB/WebBrowser/WebBrowserControl/TESTFILE... "<?xml version=""1.0""?>","<XMLTest>" ^FileOpen(1, "C:\vb\WebBrowser\WebBrowserControl\TESTFILE.XML", OpenMode.Output) Write(1, "<?xml version=""1.0""?>") The error on top occurs when creating the file. I can see that the
1
1559
by: ReidarT | last post by:
The former post was wrong, the lines where concatenated so here it goes again. I am wrriting to a file (XML-format) and using FileOpen(1, "C:\vb\WebBrowser\WebBrowserControl\TESTFILE.XML", OpenMode.Output) Write(1, "<?xml version=""1.0""?>") ....
2
1554
by: Amongin Ewinyu | last post by:
Hi, I'm trying to create a Windows service programmatically that will do the following: - When a user logs on, it will automatically run a service that uses BITS (Background Intelligent Transfer Service) to check for the most current version of a file and downloads this version. I have a wrapper class thats imported as a reference in order for me to be
1
1712
by: Dror Hershkovitz. | last post by:
Hello, I'm compiling an .exe file on VS2005 under C++ without framework support. For some reason, when I look at the properties of the .exe file there is no version tab although the project does have a resource file and the file version is defined there. I tried to create a new project and go over the projects settings and see if there is any difference but I found none.
4
2061
by: joerozario | last post by:
In .net 2005 I have created Application I want to create a log file, which maintains all the internal process so at the run time I want to create a file at the source Code: Private string LogFileName = "ADM_Log.txt"; LogFileName = Application.ExecutablePath + "\\" + LogFileName;
4
1689
by: Dica | last post by:
we just ordered VS 2005 standard edition. i was reading up on creating windows services and apparently this is only possible with the enterprise edition. is this true, or does it simply mean there's no template for windows services with the standard edition? are there VS templates published by 3rd parties i can download to ease implementation? tks
3
2280
by: XDeveloper | last post by:
Hi Dear Fellows! I recently have passed Java! And I choose C++ way! So and now I need to understand how can I built below problem! With a binary file operations of addition, removal and replacement of record are carried out. To write function by means of which primary input of the information from the keyboard and rewriting in a file is carried out. To write function, transformed data of an initial file to a text file in the form of the...
0
10325
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10148
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10091
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9950
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8972
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3646
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.