예제 #1
0
        internal SimpleFileLog(string absolutePath, int size)
        {
            // Open the log.
            // First, we try to open an existing log-- if that doesn't
            // work, we create a new one.
            //
            bool loaded = false;
            ILog log    = (ILog) new SimpleFileBasedLog();

            try
            {
                if (File.Exists(absolutePath))
                {
                    try
                    {
                        IPersistFile ipf = (IPersistFile)log;
                        ipf.Load(absolutePath, (int)STGM.ReadWrite);
                        loaded = true;
                    }
                    catch (FileNotFoundException)
                    {
                        // File not found, create a new one.
                    }
                }

                if (!loaded)
                {
                    // File does not exist.  Attempt to create a new one,
                    // with the specified size.
                    //
                    IFileBasedLogInit logInit = (IFileBasedLogInit)log;
                    logInit.InitNew(absolutePath, size);
                }

                log.SetAccessPolicyHint(RECORD_READING_POLICY.RANDOM);
                this.smuggledLog = new SmuggledIUnknown(log);
            }
            catch (COMException exception)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ConvertKnownException(exception));
            }
            catch (FileNotFoundException)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.GetString(SR.Argument_FileNameInvalid)));
            }
            finally
            {
                SafeRelease(log);
            }
        }
예제 #2
0
        internal SimpleFileLog(string absolutePath, int size)
        {
            // Open the log.
            // First, we try to open an existing log-- if that doesn't
            // work, we create a new one.
            //
            bool loaded = false;
            ILog log = (ILog)new SimpleFileBasedLog();
            try
            {
                if (File.Exists(absolutePath))
                {
                    try
                    {
                        IPersistFile ipf = (IPersistFile)log;
                        ipf.Load(absolutePath, (int)STGM.ReadWrite);
                        loaded = true;
                    }
                    catch (FileNotFoundException)
                    {
                        // File not found, create a new one.
                    }
                }

                if (!loaded)
                {
                    // File does not exist.  Attempt to create a new one,
                    // with the specified size.
                    //
                    IFileBasedLogInit logInit = (IFileBasedLogInit)log;
                    logInit.InitNew(absolutePath, size);
                }

                log.SetAccessPolicyHint(RECORD_READING_POLICY.RANDOM);
                this.smuggledLog = new SmuggledIUnknown(log);
            }
            catch (COMException exception)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ConvertKnownException(exception));
            }
            catch (FileNotFoundException)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.GetString(SR.Argument_FileNameInvalid)));
            }
            finally
            {
                SafeRelease(log);
            }
        }