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>