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 / Visual Studio.NET / Enterprise Tools / March 2005

Tip: Looking for answers? Try searching our database.

Problem with Logging block

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Tankut - 24 Mar 2005 09:07 GMT
Hi all,

I have developed a windows app. referencing a class library of my own and
both are using the entlib blocks. I have a configuration fileset including
logging, caching and custom config for my own data access library.
The problem is 'Logger.write("mymessage")' statements seem to do nothing
within the windows app. although the referenced class library logs without
problem (using the app's config). Using a flat file sink, text formatter.
There's no filter on category or priority.
I'm real close to go nuts, any comments appreciated.
Tankut - 24 Mar 2005 09:57 GMT
Hi,
For anybody interested, I have spotted the issue.
The log IS written BUT guess where?
The name of the flat file sink was stated as "myfile.log" with no preceding
directory.
THe logging block opens creates file without  problem in the directory my
exe is located, and writes the entries until...
The windows app. uses an openfile dialog and after the second the openfile
dialog is used A NEW log file is created at the directory where the openfile
dialog pointed earlier. But I, having seen the first file created normally
open it and see no entries after openfile action. This is the user
perspective, the BUG lies in the WriteMessageToFile method of FlatFileSink
class :
       private void WriteMessageToFile(LogEntry logEntry)
       {
           FlatFileSinkData flatFileSinkData =
GetFlatFileSinkDataFromCursor();
           string directory =
Path.GetDirectoryName(flatFileSinkData.FileName);
           if (directory.Length == 0)
           {
               directory = AppDomain.CurrentDomain.BaseDirectory;
           }
           if (!Directory.Exists(directory))
           {
               Directory.CreateDirectory(directory);
           }
           using (FileStream fileStream = new
FileStream(flatFileSinkData.FileName,
                                                         FileMode.Append,
FileAccess.Write, FileShare.ReadWrite))
           {
               using (StreamWriter writer = new StreamWriter(fileStream))
               {
                   lock (syncObject)
                   {
                       if (flatFileSinkData.Header.Length > 0)
                       {
                           writer.WriteLine(flatFileSinkData.Header);
                       }
                       writer.WriteLine(FormatEntry(logEntry));
                       if (flatFileSinkData.Footer.Length > 0)
                       {
                           writer.WriteLine(flatFileSinkData.Footer);
                       }

                       writer.Flush();
                   }
               }
           }
       }

You see if the filename is short, directory variable is set from current
appDomain base directory whish is perfect but it is not passed to FileStream.
I think the real problem is the FileStream class which stupidly opens the
file to the location openfile dialog last pointed.
Anyways, this is the story.

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.