473,799 Members | 3,093 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Variable for initializeData in web.config

I have created a trace listener and would like to give it a variable so
that when it is installed on a machine I have no control over it can
still find its logfile. Right now they are hardcoded as
"C:\Inetpub\www root\website\lo g1.txt" is there a way to insert
something like "~/logfile.txt")

blizzardice

<code>
<sharedListener s>
<add name="FileLogLi stener"
type="System.Di agnostics.TextW riterTraceListe ner"
initializeData= "C:\Inetpub\www root\website\lo g1.txt"/>

</code>

Aug 1 '06 #1
3 8234

gs***@blizzardi ce.com wrote:
I have created a trace listener and would like to give it a variable so
that when it is installed on a machine I have no control over it can
still find its logfile. Right now they are hardcoded as
"C:\Inetpub\www root\website\lo g1.txt" is there a way to insert
something like "~/logfile.txt")

blizzardice

<code>
<sharedListener s>
<add name="FileLogLi stener"
type="System.Di agnostics.TextW riterTraceListe ner"
initializeData= "C:\Inetpub\www root\website\lo g1.txt"/>

</code>

Another Option I could possibly do is add the tracelistener in the
application_Sta rt. However I can't seem to add it to the sourcetrace
listener only the trace. Does someone have an idea for that?

<code>
Sub Application_Sta rt(ByVal sender As Object, ByVal e As EventArgs)
' ' Code that runs on application startup
' 'Set the path to the directory for the log files, Shapefiles,
and other misc files. Basically its the application startupPath
try
dim fs as System.IO.FileS tream
dim filenamestring as String
filenamestring =
system.Configur ation.Configura tionSettings.Ap pSettings("Trac eLog")
'Todo Get this to get the path from the config file
'fs = new
System.IO.FileS tream(system.Co nfiguration.Con figurationSetti ngs.AppSettings ("TraceLog"),sy stem.IO.filemod e.OpenOrCreate, IO.FileAccess.R eadWrite,IO.Fil eShare.ReadWrit e)
fs = new
System.IO.FileS tream(server.Ma pPath(filenames tring),system.I O.filemode.Open OrCreate,IO.Fil eAccess.ReadWri te,IO.FileShare .ReadWrite)

dim sw as System.IO.Strea mWriter
sw = new System.IO.Strea mWriter(fs,syst em.Text.Encodin g.UTF8)
dim txtListener as system.Diagnost ics.TextWriterT raceListener
txtlistener = new
System.Diagnost ics.TextWriterT raceListener(sw ,"txt_Listener" )
system.Diagnost ics.Trace.Liste ners.Add(txtlis tener)
system.Diagnost ics.Trace.AutoF lush = True
dim ts as System.Diagnost ics.TraceSource
ts = new System.Diagnost ics.TraceSource ("DefaultSource 2")
ts.Listeners.Ad d(txtlistener)

catch ex as Exception
throw

my.Log.WriteExc eption(ex,Diagn ostics.TraceEve ntType.Error,"A pplication_Star t",-12)

finally

end try
End Sub

</Code>

<Config>
<system.diagnos tics>

<sources>
<source name="DefaultSo urce" switchName="Def aultSwitch">
<listeners>
<add name="FileLogLi stener"/>
<add name="EventLogL istener"/>
</listeners>
</source>
</sources>
<!--Setup logging verboseness-->
<switches>
<add name="DefaultSw itch" value="verbose"/>
</switches>
</config>

Aug 1 '06 #2
Here is some sample code from a similar post by Steven Cheng of MS that works:

protected void Application_Sta rt(Object sender, EventArgs e)
{
FileStream fs = new
FileStream(Serv er.MapPath("~/logfiles/traceLog.txt"), FileMode.OpenOr Create,F
ileAccess.ReadW rite, FileShare.ReadW rite);
StreamWriter sw = new StreamWriter(fs ,System.Text.En coding.UTF8);

System.Diagnost ics.TextWriterT raceListener txtListener = new
System.Diagnost ics.TextWriterT raceListener(sw , "txt_listener") ;

System.Diagnost ics.Trace.Liste ners.Add(txtLis tener);

System.Diagnost ics.Trace.AutoF lush = true;
}

You could modify this to use your Server.MapPath arrangement if needed.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"gs***@blizzard ice.com" wrote:
>
gs***@blizzardi ce.com wrote:
I have created a trace listener and would like to give it a variable so
that when it is installed on a machine I have no control over it can
still find its logfile. Right now they are hardcoded as
"C:\Inetpub\www root\website\lo g1.txt" is there a way to insert
something like "~/logfile.txt")

blizzardice

<code>
<sharedListener s>
<add name="FileLogLi stener"
type="System.Di agnostics.TextW riterTraceListe ner"
initializeData= "C:\Inetpub\www root\website\lo g1.txt"/>

</code>


Another Option I could possibly do is add the tracelistener in the
application_Sta rt. However I can't seem to add it to the sourcetrace
listener only the trace. Does someone have an idea for that?

<code>
Sub Application_Sta rt(ByVal sender As Object, ByVal e As EventArgs)
' ' Code that runs on application startup
' 'Set the path to the directory for the log files, Shapefiles,
and other misc files. Basically its the application startupPath
try
dim fs as System.IO.FileS tream
dim filenamestring as String
filenamestring =
system.Configur ation.Configura tionSettings.Ap pSettings("Trac eLog")
'Todo Get this to get the path from the config file
'fs = new
System.IO.FileS tream(system.Co nfiguration.Con figurationSetti ngs.AppSettings ("TraceLog"),sy stem.IO.filemod e.OpenOrCreate, IO.FileAccess.R eadWrite,IO.Fil eShare.ReadWrit e)
fs = new
System.IO.FileS tream(server.Ma pPath(filenames tring),system.I O.filemode.Open OrCreate,IO.Fil eAccess.ReadWri te,IO.FileShare .ReadWrite)

dim sw as System.IO.Strea mWriter
sw = new System.IO.Strea mWriter(fs,syst em.Text.Encodin g.UTF8)
dim txtListener as system.Diagnost ics.TextWriterT raceListener
txtlistener = new
System.Diagnost ics.TextWriterT raceListener(sw ,"txt_Listener" )
system.Diagnost ics.Trace.Liste ners.Add(txtlis tener)
system.Diagnost ics.Trace.AutoF lush = True
dim ts as System.Diagnost ics.TraceSource
ts = new System.Diagnost ics.TraceSource ("DefaultSource 2")
ts.Listeners.Ad d(txtlistener)

catch ex as Exception
throw

my.Log.WriteExc eption(ex,Diagn ostics.TraceEve ntType.Error,"A pplication_Star t",-12)

finally

end try
End Sub

</Code>

<Config>
<system.diagnos tics>

<sources>
<source name="DefaultSo urce" switchName="Def aultSwitch">
<listeners>
<add name="FileLogLi stener"/>
<add name="EventLogL istener"/>
</listeners>
</source>
</sources>
<!--Setup logging verboseness-->
<switches>
<add name="DefaultSw itch" value="verbose"/>
</switches>
</config>

Aug 1 '06 #3
Yes it works (make sure the logfiles directory is already created) ,
however I'd also like my trace entries to have a timestamp so I figured I
could set the properties on the trace listener to accomplish this but THAT
that doesn't see to work .

txtListener.Tra ceOutputOptions = TraceOptions.Da teTime

but log entries don't get any time info when written. I'm certain there is
something else needs to be done but really can't imagine what it is .

Any ideas ?
thanks


"Peter Bromberg [C# MVP]" wrote:
Here is some sample code from a similar post by Steven Cheng of MS that works:

protected void Application_Sta rt(Object sender, EventArgs e)
{
FileStream fs = new
FileStream(Serv er.MapPath("~/logfiles/traceLog.txt"), FileMode.OpenOr Create,F
ileAccess.ReadW rite, FileShare.ReadW rite);
StreamWriter sw = new StreamWriter(fs ,System.Text.En coding.UTF8);

System.Diagnost ics.TextWriterT raceListener txtListener = new
System.Diagnost ics.TextWriterT raceListener(sw , "txt_listener") ;

System.Diagnost ics.Trace.Liste ners.Add(txtLis tener);

System.Diagnost ics.Trace.AutoF lush = true;
}

You could modify this to use your Server.MapPath arrangement if needed.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"gs***@blizzard ice.com" wrote:

gs***@blizzardi ce.com wrote:
I have created a trace listener and would like to give it a variable so
that when it is installed on a machine I have no control over it can
still find its logfile. Right now they are hardcoded as
"C:\Inetpub\www root\website\lo g1.txt" is there a way to insert
something like "~/logfile.txt")
>
blizzardice
>
<code>
<sharedListener s>
<add name="FileLogLi stener"
type="System.Di agnostics.TextW riterTraceListe ner"
initializeData= "C:\Inetpub\www root\website\lo g1.txt"/>
>
</code>

Another Option I could possibly do is add the tracelistener in the
application_Sta rt. However I can't seem to add it to the sourcetrace
listener only the trace. Does someone have an idea for that?

<code>
Sub Application_Sta rt(ByVal sender As Object, ByVal e As EventArgs)
' ' Code that runs on application startup
' 'Set the path to the directory for the log files, Shapefiles,
and other misc files. Basically its the application startupPath
try
dim fs as System.IO.FileS tream
dim filenamestring as String
filenamestring =
system.Configur ation.Configura tionSettings.Ap pSettings("Trac eLog")
'Todo Get this to get the path from the config file
'fs = new
System.IO.FileS tream(system.Co nfiguration.Con figurationSetti ngs.AppSettings ("TraceLog"),sy stem.IO.filemod e.OpenOrCreate, IO.FileAccess.R eadWrite,IO.Fil eShare.ReadWrit e)
fs = new
System.IO.FileS tream(server.Ma pPath(filenames tring),system.I O.filemode.Open OrCreate,IO.Fil eAccess.ReadWri te,IO.FileShare .ReadWrite)

dim sw as System.IO.Strea mWriter
sw = new System.IO.Strea mWriter(fs,syst em.Text.Encodin g.UTF8)
dim txtListener as system.Diagnost ics.TextWriterT raceListener
txtlistener = new
System.Diagnost ics.TextWriterT raceListener(sw ,"txt_Listener" )
system.Diagnost ics.Trace.Liste ners.Add(txtlis tener)
system.Diagnost ics.Trace.AutoF lush = True
dim ts as System.Diagnost ics.TraceSource
ts = new System.Diagnost ics.TraceSource ("DefaultSource 2")
ts.Listeners.Ad d(txtlistener)

catch ex as Exception
throw

my.Log.WriteExc eption(ex,Diagn ostics.TraceEve ntType.Error,"A pplication_Star t",-12)

finally

end try
End Sub

</Code>

<Config>
<system.diagnos tics>

<sources>
<source name="DefaultSo urce" switchName="Def aultSwitch">
<listeners>
<add name="FileLogLi stener"/>
<add name="EventLogL istener"/>
</listeners>
</source>
</sources>
<!--Setup logging verboseness-->
<switches>
<add name="DefaultSw itch" value="verbose"/>
</switches>
</config>
Aug 21 '06 #4

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

Similar topics

7
7226
by: Billy Jacobs | last post by:
I am having a problem with my session variable being set to Null for no apparent reason. I am declaring it like the following when the user logs in. dim objUserInfo as new clsUserInfo 'Set some properties objUserInfo.UserName = txtUserName.text.trim objUserInfo...
11
4223
by: Paul D.Smith | last post by:
Can Python create a variable "on-the-fly". For example I would like something like... make_variable('OSCAR', 'the grouch'); print OSCAR; ....to output... the grouch
17
4459
by: Mike L | last post by:
This is for a Win form. Currently I have several connection strings that are identical through out my application. Is a global variable the best choice for this situation? If so, what is the code to make a global string variable, and where do I put it, (before the namespace, of just under it)?????
7
2171
by: Greg Collins [MVP] | last post by:
Hi, I couldn't find what I was looking for by searching the newsgroup, but perhaps these have already been discussed somewhere. This is a bit long with a lot of interrelated questions. What I've got is a decodeImage.aspx page that gets called to decode base64 encoded images and return them as displayable images to a Web page. The ASPX page is passed two parameters, "file" and "img". The "file" parameter specifies and XML file on the Web...
41
10680
by: Miguel Dias Moura | last post by:
Hello, I am working on an ASP.NET / VB page and I created a variable "query": Sub Page_Load(sender As Object, e As System.EventArgs) Dim query as String = String.Empty ... query = String.Format("SELECT * FROM dbo.documents WHERE ") & query End Sub
2
2345
by: simon | last post by:
hello, what i'm looking to do is store the path of the app on a the server for reuse in the site. my thoughts so far are... -make a key in the web.config file -retrieve the value in globals.asax in application startup -store it in a variable that can be reference from all pages -use that variable on many pages my questions 1) what is the syntax of the lines in global.asax page to put this
12
7940
by: Chris Allen | last post by:
Hello fellow pythoneers. I'm stumped on something, and I was hoping maybe someone in here would have an elegant solution to my problem. This is the first time I've played around with packages, so I'm probably misunderstanding something here... Here's what I'd like to do in my package. I want my package to use a configuration file, and what I'd like is for the config file to appear magically in each module so I can just grab values from...
2
2665
by: | last post by:
I set up a TextWriterTraceListener in the App.config file. I'd like to be able to tell, programmatically, which file it's using. However, I don't seem to be able to get at the initializeData attribute. The Attribute collection attached to the TextWriterTraceListener is empty. Any ideas as to how I might get at this file name without having to parse App.config?
0
9685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9538
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10219
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
10025
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
9068
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...
1
7563
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5584
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4138
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
3
2937
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.