gs***@blizzardice.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\wwwroot\website\log1.txt" is there a way to insert
something like "~/logfile.txt")
blizzardice
<code>
<sharedListeners>
<add name="FileLogListener"
type="System.Diagnostics.TextWriterTraceListener"
initializeData="C:\Inetpub\wwwroot\website\log1.tx t"/>
</code>
Another Option I could possibly do is add the tracelistener in the
application_Start. 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_Start(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.FileStream
dim filenamestring as String
filenamestring =
system.Configuration.ConfigurationSettings.AppSett ings("TraceLog")
'Todo Get this to get the path from the config file
'fs = new
System.IO.FileStream(system.Configuration.Configur ationSettings.AppSettings("TraceLog"),system.IO.fi lemode.OpenOrCreate,IO.FileAccess.ReadWrite,IO.Fil eShare.ReadWrite)
fs = new
System.IO.FileStream(server.MapPath(filenamestring ),system.IO.filemode.OpenOrCreate,IO.FileAccess.Re adWrite,IO.FileShare.ReadWrite)
dim sw as System.IO.StreamWriter
sw = new System.IO.StreamWriter(fs,system.Text.Encoding.UTF 8)
dim txtListener as system.Diagnostics.TextWriterTraceListener
txtlistener = new
System.Diagnostics.TextWriterTraceListener(sw,"txt _Listener")
system.Diagnostics.Trace.Listeners.Add(txtlistener )
system.Diagnostics.Trace.AutoFlush = True
dim ts as System.Diagnostics.TraceSource
ts = new System.Diagnostics.TraceSource("DefaultSource2")
ts.Listeners.Add(txtlistener)
catch ex as Exception
throw
my.Log.WriteException(ex,Diagnostics.TraceEventTyp e.Error,"Application_Start",-12)
finally
end try
End Sub
</Code>
<Config>
<system.diagnostics>
<sources>
<source name="DefaultSource" switchName="DefaultSwitch">
<listeners>
<add name="FileLogListener"/>
<add name="EventLogListener"/>
</listeners>
</source>
</sources>
<!--Setup logging verboseness-->
<switches>
<add name="DefaultSwitch" value="verbose"/>
</switches>
</config>