UdpAppender
...
{this.RemoteEndPoint = new IPEndPoint(this.RemoteAddress, this.RemotePort); if (this.LocalPort == 0) ...{ this.Client = new UdpClient(); } else ...{ this.Client = new UdpClient(this.LocalPort); } Byte [] buffer = m_encoding.GetBytes(RenderLoggingEvent(loggingEvent).ToCharArray()); this.Client.Send(buffer, buffer.Length, this.RemoteEndPoint); }
SmtpPickupDirAppender
...
{ string filePath = null; StreamWriter writer = null; // Impersonate to open the file using(SecurityContext.Impersonate(this)) ...{ filePath = Path.Combine(m_pickupDir, SystemInfo.NewGuid().ToString("N")); writer = File.CreateText(filePath); } using(writer) ...{ writer.WriteLine("To: " + m_to); writer.WriteLine("From: " + m_from); writer.WriteLine("Subject: " + m_subject); writer.WriteLine(""); }}
EventLogAppender
...
{EventLog.DeleteEventSource(m_applicationName, m_machineName);EventLog.CreateEventSource(source, logName, machineName);registeredLogName = EventLog.LogNameFromSourceName(m_applicationName, m_machineName);EventLog.WriteEntry(m_applicationName, eventTxt, entryType, eventID);}
SmtpAppender
...
{#if NET_2_0 // .NET 2.0 has a new API for SMTP email System.Net.Mail // This API supports credentials and multiple hosts correctly. // The old API is deprecated. // Create and configure the smtp client SmtpClient smtpClient = new SmtpClient(); if (m_smtpHost != null && m_smtpHost.Length > 0) ...{ smtpClient.Host = m_smtpHost; } smtpClient.Port = m_port; smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network; if (m_authentication == SmtpAuthentication.Basic) ...{ // Perform basic authentication smtpClient.Credentials = new System.Net.NetworkCredential(m_username, m_password); } else if (m_authentication == SmtpAuthentication.Ntlm) ...{ // Perform integrated authentication (NTLM) smtpClient.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials; } MailMessage mailMessage = new MailMessage(); mailMessage.Body = messageBody; mailMessage.From = new MailAddress(m_from); mailMessage.To.Add(m_to); mailMessage.Subject = m_subject; mailMessage.Priority = m_mailPriority; // TODO: Consider using SendAsync to send the message without blocking. This would be a change in // behaviour compared to .NET 1.x. We would need a SendCompletedCallback to log errors. smtpClient.Send(mailMessage);#else // .NET 1.x uses the System.Web.Mail API for sending Mail MailMessage mailMessage = new MailMessage(); mailMessage.Body = messageBody; mailMessage.From = m_from; mailMessage.To = m_to; mailMessage.Subject = m_subject; mailMessage.Priority = m_mailPriority;#if NET_1_1 // The Fields property on the MailMessage allows the CDO properties to be set directly. // This property is only available on .NET Framework 1.1 and the implementation must understand // the CDO properties. For details of the fields available in CDO see: // // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cdosys/html/_cdosys_configuration_coclass.asp // try ...{ if (m_authentication == SmtpAuthentication.Basic) ...{ // Perform basic authentication mailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", 1); mailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", m_username); mailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", m_password); } else if (m_authentication == SmtpAuthentication.Ntlm) ...{ // Perform integrated authentication (NTLM) mailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", 2); } // Set the port if not the default value if (m_port != 25) ...{ mailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", m_port); } } catch(MissingMethodException missingMethodException) ...{ // If we were compiled against .NET 1.1 but are running against .NET 1.0 then // we will get a MissingMethodException when accessing the MailMessage.Fields property. ErrorHandler.Error("SmtpAppender: Authentication and server Port are only supported when running on the MS .NET 1.1 framework", missingMethodException); }#else if (m_authentication != SmtpAuthentication.None) ...{ ErrorHandler.Error("SmtpAppender: Authentication is only supported on the MS .NET 1.1 or MS .NET 2.0 builds of log4net"); } if (m_port != 25) ...{ ErrorHandler.Error("SmtpAppender: Server Port is only supported on the MS .NET 1.1 or MS .NET 2.0 builds of log4net"); }#endif // if NET_1_1 if (m_smtpHost != null && m_smtpHost.Length > 0) ...{ SmtpMail.SmtpServer = m_smtpHost; } SmtpMail.Send(mailMessage);#endif // if NET_2_0}
NetSendAppender
...
{[DllImport("netapi32.dll", SetLastError=true)] protected static extern int NetMessageBufferSend( [MarshalAs(UnmanagedType.LPWStr)] string serverName, [MarshalAs(UnmanagedType.LPWStr)] string msgName, [MarshalAs(UnmanagedType.LPWStr)] string fromName, [MarshalAs(UnmanagedType.LPWStr)] string buffer, int bufferSize);int returnValue = NetMessageBufferSend(this.Server, this.Recipient, this.Sender, renderedLoggingEvent, renderedLoggingEvent.Length * Marshal.SystemDefaultCharSize); }
ColoredConsoleAppender
...
{ private const UInt32 STD_OUTPUT_HANDLE = unchecked((UInt32)(-11)); private const UInt32 STD_ERROR_HANDLE = unchecked((UInt32)(-12)); [DllImport("Kernel32.dll", SetLastError=true, CharSet=CharSet.Auto)] private static extern IntPtr GetStdHandle( [DllImport("Kernel32.dll", SetLastError=true, CharSet=CharSet.Auto)] private static extern int GetConsoleOutputCP(); [DllImport("Kernel32.dll", SetLastError=true, CharSet=CharSet.Auto)] private static extern bool SetConsoleTextAttribute( IntPtr consoleHandle, ushort attributes); [DllImport("Kernel32.dll", SetLastError=true, CharSet=CharSet.Auto)] private static extern bool GetConsoleScreenBufferInfo( IntPtr consoleHandle, out CONSOLE_SCREEN_BUFFER_INFO bufferInfo); UInt32 type);IntPtr consoleHandle = IntPtr.Zero; if (m_writeToErrorStream) ...{ // Write to the error stream consoleHandle = GetStdHandle(STD_ERROR_HANDLE); } else ...{ // Write to the output stream consoleHandle = GetStdHandle(STD_OUTPUT_HANDLE); }CONSOLE_SCREEN_BUFFER_INFO bufferInfo; GetConsoleScreenBufferInfo(consoleHandle, out bufferInfo); // set the console colors SetConsoleTextAttribute(consoleHandle, colorInfo); m_consoleOutputWriter.Write(messageCharArray, 0, arrayLength); // Restore the console back to its previous color scheme SetConsoleTextAttribute(consoleHandle, bufferInfo.wAttributes);}
RemotingAppender
...
{m_sinkObj = (IRemoteLoggingSink)Activator.GetObject(typeof(IRemoteLoggingSink), m_sinkUrl, channelProperties);m_sinkObj.LogEvents(events);}
AspNetTraceAppender
...
{ if (HttpContext.Current != null) ...{ // check if tracing is enabled for the current context if (HttpContext.Current.Trace.IsEnabled) ...{ if (loggingEvent.Level >= Level.Warn) ...{ HttpContext.Current.Trace.Warn(loggingEvent.LoggerName, RenderLoggingEvent(loggingEvent)); } else ...{ HttpContext.Current.Trace.Write(loggingEvent.LoggerName, RenderLoggingEvent(loggingEvent)); } } }}
AdoNetAppender
...
{//"System.Data.OracleClient.OracleConnection, System.Data.OracleClient, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"IDbConnection m_dbConnection = (IDbConnection)Activator.CreateInstance(ResolveConnectionType());m_dbConnection.Open();dbTran = m_dbConnection.BeginTransaction();IDbCommand m_dbCommand = m_dbConnection.CreateCommand();m_dbCommand.Transaction = dbTran;foreach(AdoNetAppenderParameter param in m_parameters) ...{ param.FormatValue(m_dbCommand, e); } // Execute the query m_dbCommand.ExecuteNonQuery(); // commit transaction dbTran.Commit();m_dbConnection.Close();}
转载请注明原文地址: https://ibbs.8miu.com/read-24788.html