Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / January 2005

Tip: Looking for answers? Try searching our database.

Trace question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Spyros - 27 Dec 2004 17:15 GMT
I am using Trace in order to log information about the behavior of a web
application.  In web.config I have defined my Application Listener as
following:
<trace autoflush="true" indentsize="4">
  <listeners>
    <add name="AppListener"
type="System.Diagnostics.TextWriterTraceListener"  
initializeData="d:\temp\activity.log" />
   <remove type="System.Diagnostics.DefaultTraceListener" />
  </listeners>
</trace>

As you can see all activity is logged in "d:\temp\activity.log".  Is there a
way to make this variable, that is changing by date automatically, such as:
activity20041201.log,
activity20041202.log,
activity20041203.log etc.

Thank you for your time
Cowboy (Gregory A. Beamer) - MVP - 28 Dec 2004 03:25 GMT
Not that I know of using the standard .NET FUD. If you want full control,
consider some other form of instrumentation for your application. If you are
really brave, the Enterprise Instrumentation project (MSDN Universal) gives
you real power. For simple logging, however, a variation of the Exception
Management Block (a free download) is an option, as is a custom logger. If
you are stuck on Trace, you have the option of creating your own custom Trace
Listener, which can log wherever you desire.

---

Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************

> I am using Trace in order to log information about the behavior of a web
> application.  In web.config I have defined my Application Listener as
[quoted text clipped - 15 lines]
>
> Thank you for your time
Richard Grimes [MVP] - 01 Jan 2005 16:29 GMT
> I am using Trace in order to log information about the behavior of a
> web application.  In web.config I have defined my Application
[quoted text clipped - 13 lines]
> activity20041202.log,
> activity20041203.log etc.

Its easy to create your own trace listener class:

class DateTraceListener : TextWriterTraceListener
{
  public DateTraceListener()
  {
     Name="DateTraceListener";
     Initialize();
  }
  protected void Initialize()
  {
     string strFile = "Activity"
//         + "." + Thread.GetDomainID.ToString() + "."
        + DateTime.Now.ToShortDateString()
        + ".log";
     this.Writer = new StreamWriter(strFile, true);
  }

}

Use this class instead of TextWriterTraceListener in your config file. (You
need to priovide a fully qualified name, including the assembly name.)

Note the bit I commented out. There's a bug in TextWriterTraceListener that
if you use it from a config file and trace from two appdomains in the
process then the second appdomain will fail because the first appdomain will
have exclusive access to the log file. If you name the file according to the
appdomain name (or in this case the ID) then you avoid this issue. The
ToShortDateString() probably does not return the right format, but its easy
to create the right format with the DataTime properties. Note that you do
not need to use initializeData in your config file.

Finally, to get a new file every day you'll have to close down the instance
of DateTraceListener and create a new one. Unfortunately there's no elegant
way to do this. One solution would be to have a background thread running
and when the date changes it could remove and dispose the DateTraceListener
in the Trace.Listeners collection and then create a new instance and add it
to the collection.

Richard
Signature

www.richardgrimes.com
my email evpuneqt@zicf.bet is encrypted with ROT13 (www.rot13.org)


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.