Esempio n. 1
0
            /// <summary>
            /// Close all network connections
            /// </summary>
            /// <remarks>
            /// <para>
            /// Make sure we close all network connections
            /// </para>
            /// </remarks>
            public void Dispose()
            {
                foreach (SocketClient client in m_clients)
                {
                    client.Dispose();
                }
                m_clients.Clear();
                Socket serverSocket = m_serverSocket;

                m_serverSocket = null;
                try
                {
                    serverSocket.Shutdown(SocketShutdown.Both);
                }
                catch
                {
                }
                try
                {
                    CompatibilityExtensions.Close(serverSocket);
                }
                catch
                {
                }
            }
Esempio n. 2
0
 /// <summary>
 /// Helper method to close <paramref name="stream" /> under CurrentAppender's SecurityContext.
 /// </summary>
 /// <remarks>
 /// Does not set <paramref name="stream" /> to null.
 /// </remarks>
 /// <param name="stream"></param>
 protected void CloseStream(Stream stream)
 {
     using (CurrentAppender.SecurityContext.Impersonate(this))
     {
         CompatibilityExtensions.Close(stream);
     }
 }
Esempio n. 3
0
 /// <summary>
 /// Cleanup the clients connection
 /// </summary>
 /// <remarks>
 /// <para>
 /// Close the socket connection.
 /// </para>
 /// </remarks>
 public void Dispose()
 {
     try
     {
         if (m_writer != null)
         {
             CompatibilityExtensions.Close(m_writer);
             m_writer = null;
         }
     }
     catch
     {
     }
     if (m_socket != null)
     {
         try
         {
             m_socket.Shutdown(SocketShutdown.Both);
         }
         catch
         {
         }
         try
         {
             CompatibilityExtensions.Close(m_socket);
         }
         catch
         {
         }
         m_socket = null;
     }
 }
Esempio n. 4
0
 /// <summary>
 /// Closes the UDP connection and releases all resources associated with
 /// this <see cref="T:log4net.Appender.UdpAppender" /> instance.
 /// </summary>
 /// <remarks>
 /// <para>
 /// Disables the underlying <see cref="T:System.Net.Sockets.UdpClient" /> and releases all managed
 /// and unmanaged resources associated with the <see cref="T:log4net.Appender.UdpAppender" />.
 /// </para>
 /// </remarks>
 protected override void OnClose()
 {
     base.OnClose();
     if (Client != null)
     {
         CompatibilityExtensions.Close(Client);
         Client = null;
     }
 }
Esempio n. 5
0
        private static void InternalConfigure(ILoggerRepository repository, Uri configUri)
        {
            LogLog.Debug(declaringType, "configuring repository [" + repository.Name + "] using URI [" + configUri + "]");
            if (configUri == null)
            {
                LogLog.Error(declaringType, "Configure called with null 'configUri' parameter");
                return;
            }
            if (configUri.IsFile)
            {
                InternalConfigure(repository, new FileInfo(configUri.LocalPath));
                return;
            }
            WebRequest webRequest = null;

            try
            {
                webRequest = WebRequest.Create(configUri);
            }
            catch (Exception exception)
            {
                LogLog.Error(declaringType, "Failed to create WebRequest for URI [" + configUri + "]", exception);
            }
            if (webRequest != null)
            {
                try
                {
                    webRequest.Credentials = CredentialCache.DefaultCredentials;
                }
                catch
                {
                }
                try
                {
                    WebResponse result = webRequest.GetResponseAsync().GetAwaiter().GetResult();
                    if (result != null)
                    {
                        try
                        {
                            using (Stream configStream = result.GetResponseStream())
                            {
                                InternalConfigure(repository, configStream);
                            }
                        }
                        finally
                        {
                            CompatibilityExtensions.Close(result);
                        }
                    }
                }
                catch (Exception exception2)
                {
                    LogLog.Error(declaringType, "Failed to request config from URI [" + configUri + "]", exception2);
                }
            }
        }
Esempio n. 6
0
 private static void InternalConfigure(ILoggerRepository repository, FileInfo configFile)
 {
     LogLog.Debug(declaringType, "configuring repository [" + repository.Name + "] using file [" + configFile + "]");
     if (configFile == null)
     {
         LogLog.Error(declaringType, "Configure called with null 'configFile' parameter");
     }
     else if (File.Exists(configFile.FullName))
     {
         FileStream fileStream = null;
         int        num        = 5;
         while (--num >= 0)
         {
             try
             {
                 fileStream = configFile.Open(FileMode.Open, FileAccess.Read, FileShare.Read);
             }
             catch (IOException exception)
             {
                 if (num == 0)
                 {
                     LogLog.Error(declaringType, "Failed to open XML config file [" + configFile.Name + "]", exception);
                     fileStream = null;
                 }
                 Thread.Sleep(250);
                 continue;
             }
             break;
         }
         if (fileStream != null)
         {
             try
             {
                 InternalConfigure(repository, fileStream);
             }
             finally
             {
                 CompatibilityExtensions.Close(fileStream);
             }
         }
     }
     else
     {
         LogLog.Debug(declaringType, "config file [" + configFile.FullName + "] not found. Configuration unchanged.");
     }
 }
Esempio n. 7
0
        /// <summary>
        /// Produces a formatted string.
        /// </summary>
        /// <param name="loggingEvent">The event being logged.</param>
        /// <param name="writer">The TextWriter to write the formatted event to</param>
        /// <remarks>
        /// <para>
        /// Format the <see cref="T:log4net.Core.LoggingEvent" /> and write it to the <see cref="T:System.IO.TextWriter" />.
        /// </para>
        /// <para>
        /// This method creates an <see cref="T:System.Xml.XmlTextWriter" /> that writes to the
        /// <paramref name="writer" />. The <see cref="T:System.Xml.XmlTextWriter" /> is passed
        /// to the <see cref="M:log4net.Layout.XmlLayoutBase.FormatXml(System.Xml.XmlWriter,log4net.Core.LoggingEvent)" /> method. Subclasses should override the
        /// <see cref="M:log4net.Layout.XmlLayoutBase.FormatXml(System.Xml.XmlWriter,log4net.Core.LoggingEvent)" /> method rather than this method.
        /// </para>
        /// </remarks>
        public override void Format(TextWriter writer, LoggingEvent loggingEvent)
        {
            if (loggingEvent == null)
            {
                throw new ArgumentNullException("loggingEvent");
            }
            XmlWriterSettings settings = new XmlWriterSettings
            {
                Indent             = false,
                OmitXmlDeclaration = true
            };
            XmlWriter xmlWriter = XmlWriter.Create(new ProtectCloseTextWriter(writer), settings);

            FormatXml(xmlWriter, loggingEvent);
            xmlWriter.WriteWhitespace(SystemInfo.NewLine);
            CompatibilityExtensions.Close(xmlWriter);
        }