Join 34,000+ subscribers and receive articles from our
blog about software quality, testing, QA and security.

Log problem on the windows 2008 (64bit os)


#1

I made delphi procedure.
It working good on the Windows 7 OS.
But it has a problem on the Windows 2008 OS.
My application is Windows Service application.

Problem is …
logfile size is 0 byte until my service application running.
But… when my service applicatin stop, log file size was increased.
( it means Smart Inspector does not flush buffer to disk while service applicaion running.
This probloem only occured on the windows 2008 server os except Windows 7 Os )

------- delphi procedure code -----

procedure StartLogging;
var
aParam: string;
FilePath: string;
begin
FilePath := ExtractFilePath( ParamStr(0) ) + ‘Log’;
if not DirectoryExists(FilePath) then ForceDirectories( FilePath );
FilePath := FilePath + ‘’ + ‘Log.sil’;
aParam := format(‘file(filename="%s", append=“true”, buffer=“0”, rotate=“daily”), pipe(reconnect=“true”, reconnect.interval=“60”)’, [ FilePath ] );

si.Connections := aParam;
si.Enabled := True;
end;
----------------- code end —


#2

Hello schiva,

Thanks for your posting. We haven’t seen this behavior yet but the SmartInspect Delphi library does not explicitly flush the I/O buffers of Windows after writing a log entry. So it may be that Windows 2008 behaves a bit differently than previous Windows versions with regards to the buffer. This is usually not a problem since Windows flushes the buffers eventually (and should also write the data in case of an application crash).

I hope this helps,
Tobias


#3

Thank you for your answer.

You told " Windows flushes the buffers eventually".
It measn insepector log file will be written…

But, in my test case… smartinspect log file did not flushed, although much time already gone.
( ex… log file size was 1 kbyte, althogh 20 minutes was gone.
In this case, log file size increased to 1 mbyte suddenly when my service application stopped.)

I want to know how to solve this issue ( Late log file flush on the windows 2008 server ).

Thank you again for your support.

ps) sorry for my poor english.


#4

Hello,

Could you please try to open the log file in the SmartInspect Console to check if the log file is really (nearly) empty? Also, when you view the size in the Windows Explorer, could you try to refresh the view (with F5) to check if the file size changes?

Regards,
Dennis


#5

I have the same problem (.NET, not delphi) with a service running on Windows 2012 Server. Logs do not get flushed to disk until the service is stopped.

Is there a solution to this?


#6

Thanks for your posting. Provided that you haven’t changed the default settings (specifically the “buffer” option), SmartInspect does everything it can to flush the data to disk immediately (such as calling Stream.Flush after each message) so I’m not sure what’s causing this behavior. It seems that Windows 2008/2012 changed the I/O caching behavior and there may be a Windows API method to influence this behavior for a process/application.

Regards,
Tobias


#7

I’m seeing the same thing in .net 4.5 using smartinspect.dll version 3.1.0.8000 and running my service on win 2012

I’ve reproduced this issue using a small winform test app

the last few lines of the log do not get written until I call dispose (close the service) on my smartinspect instance

I do modify the configuration - but buffer is off (set to 0)

code:

private void Form1_Load(object sender, EventArgs e)
        {
            _smartInspect = new SmartInspect(System.Reflection.Assembly.GetExecutingAssembly().GetName().Name)
            {
                Connections =
                    "file(append=\"false\", filename=\"log.sil\", buffer=\"0\", maxsize=\"10MB\", rotate=\"daily\", maxparts=\"20\", encrypt=\"true\", key=\"password\", caption=\"file\", level=\"debug\", async.enabled=\"true\")",
                Resolution = ClockResolution.Standard,
                Enabled = true,
                DefaultLevel = Level.Debug,
                Level = Level.Debug
            };

            LogStuff();
        }

        public void LogStuff()
        {
            var ses = _smartInspect.AddSession("mySession");
            ses.LogMessage("First Message!");

            for (int i = 0; i < 30; i++)
            {
                System.Threading.Thread.Sleep(500);
                ses.LogMessage(DateTime.Now.ToString());
                ses.LogObject("this obj", this);
            }
            ses.LogMessage("DONE!");
            ses.LogMessage("We're finished now!!");

            _smartInspect.DeleteSession(ses);
        }

        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            if (_smartInspect != null)
                _smartInspect.Dispose();
        }

#8

Hello,

Thanks for your posting and my apologies for the delayed response. Could you please try this again without the async and encrypt options? They both influence the flush and dispose behavior and this could be the reason for this. In general, SmartInspect does everything it can to flush the data immediately after writing a log entry to the log file.

Regards,
Tobias