public LogProvider(ILogProviderHost host, string fileName)
     :
     base(host, PlainText.Factory.Instance,
          ConnectionParamsUtils.CreateConnectionParamsWithIdentity(ConnectionParamsUtils.CreateFileBasedConnectionIdentityFromFileName(fileName)))
 {
     this.fileName = fileName;
     StartLiveLogThread(string.Format("'{0}' listening thread", fileName));
 }
Beispiel #2
0
        public LogProvider(ILogProviderHost host, Factory factory)
            :
            base(host, factory, ConnectionParamsUtils.CreateConnectionParamsWithIdentity(DebugOutput.Factory.connectionIdentity))
        {
            using (trace.NewFrame)
            {
                try
                {
                    dataReadyEvt   = new EventWaitHandle(false, EventResetMode.AutoReset, "DBWIN_DATA_READY");
                    bufferReadyEvt = new EventWaitHandle(false, EventResetMode.AutoReset, "DBWIN_BUFFER_READY");
                    trace.Info("Events opened OK. DBWIN_DATA_READY={0}, DBWIN_BUFFER_READY={1}",
                               dataReadyEvt.SafeWaitHandle.DangerousGetHandle(), bufferReadyEvt.SafeWaitHandle.DangerousGetHandle());

                    bufferFile = new SafeFileHandle(
                        Unmanaged.CreateFileMapping(new IntPtr(-1), IntPtr.Zero, Unmanaged.PAGE_READWRITE, 0, 1024, "DBWIN_BUFFER"), true);
                    if (bufferFile.IsInvalid)
                    {
                        throw new Win32Exception(Marshal.GetLastWin32Error());
                    }
                    trace.Info("DBWIN_BUFFER shared file opened OK. Handle={0}", bufferFile.DangerousGetHandle());

                    bufferAddress = new SafeViewOfFileHandle(
                        Unmanaged.MapViewOfFile(bufferFile, Unmanaged.FILE_MAP_READ, 0, 0, 512), true);
                    if (bufferAddress.IsInvalid)
                    {
                        throw new Win32Exception(Marshal.GetLastWin32Error());
                    }
                    trace.Info("View of file mapped OK. Ptr={0}", bufferAddress.DangerousGetHandle());

                    StartLiveLogThread("DebugOutput listening thread");
                }
                catch (Exception e)
                {
                    trace.Error(e, "Failed to inistalize DebugOutput reader. Disposing what has been created so far.");
                    Cleanup();
                    throw;
                }
            }
        }