Ejemplo n.º 1
0
 protected override void Convert(TextWriter writer, LoggingEvent loggingEvent)
 {
     writer.Write(LoadLog4NetConfig.GetLocalIpAddress());
 }
Ejemplo n.º 2
0
        private bool Init(XmlElement xmlElement)
        {
            if (xmlElement == null)
            {
                throw new Exception(string.Format(Constants.Error_NoConfigForModule, Constants.Module_Log_Name));
            }
            try
            {
                XElement xElement = XmlHelper.ToXElement(xmlElement);
                foreach (XElement m in xElement.Elements(LogConstants.Appender))
                {
                    if (m != null)
                    {
                        var name = m.Attribute(LogConstants.Name).Value;
                        var type = m.Attribute(LogConstants.Type).Value;
                        if (type.ToUpper() == LogConstants.Type_DataBase.ToUpper())
                        {
                            var bufferSize       = LogConstants.Config_BufferSize;
                            var bufferSizeConfig = m.Element(LogConstants.E_BufferSize);
                            if (bufferSizeConfig != null)
                            {
                                bufferSize = bufferSizeConfig.Attribute(LogConstants.Value).Value;
                            }

                            var connectionType       = LogConstants.Config_ConnectionType;
                            var connectionTypeConfig = m.Element(LogConstants.E_ConnectionType);
                            if (connectionTypeConfig != null)
                            {
                                connectionType = connectionTypeConfig.Attribute(LogConstants.Value).Value;
                            }

                            var connectionString       = LogConstants.Config_ConnectionString;
                            var connectionStringConfig = m.Element(LogConstants.E_ConnectionString);
                            if (connectionStringConfig != null)
                            {
                                connectionString = connectionStringConfig.Attribute(LogConstants.Value).Value;
                            }

                            var commandText       = LogConstants.Config_CommandText;
                            var commandTextConfgi = m.Element(LogConstants.E_CommandText);
                            if (commandTextConfgi != null)
                            {
                                commandText = commandTextConfgi.Attribute(LogConstants.Value).Value;
                            }
                            LoadLog4NetConfig.LoadADONetAppender(name, bufferSize, connectionType, connectionString, commandText);
                        }
                        else if (type.ToUpper() == LogConstants.Type_RollingFile.ToUpper())
                        {
                            var appendToFile       = LogConstants.Config_AppendToFile;
                            var appendToFileConfig = m.Element(LogConstants.E_AppendToFile);
                            if (appendToFileConfig != null)
                            {
                                appendToFile = appendToFileConfig.Attribute(LogConstants.Value).Value;
                            }

                            var datePattern       = LogConstants.Config_DatePattern;
                            var datePatternConfig = m.Element(LogConstants.E_DatePattern);
                            if (datePatternConfig != null)
                            {
                                datePattern = datePatternConfig.Attribute(LogConstants.Value).Value;
                            }

                            var file       = LogConstants.Config_File;
                            var fileConfig = m.Element(LogConstants.E_File);
                            if (fileConfig != null)
                            {
                                file = fileConfig.Attribute(LogConstants.Value).Value;
                            }

                            var maximumFileSize       = LogConstants.Config_MaximumFileSize;
                            var maximumFileSizeConfig = m.Element(LogConstants.E_MaximumFileSize);
                            if (maximumFileSizeConfig != null)
                            {
                                maximumFileSize = maximumFileSizeConfig.Attribute(LogConstants.Value).Value;
                            }

                            var maxSizeRollBackups       = LogConstants.Config_MaxSizeRollBackups;
                            var maxSizeRollBackupsConfig = m.Element(LogConstants.E_MaxSizeRollBackups);
                            if (maxSizeRollBackupsConfig != null)
                            {
                                maxSizeRollBackups = maxSizeRollBackupsConfig.Attribute(LogConstants.Value).Value;
                            }

                            var staticLogFileName       = LogConstants.Config_StaticLogFileName;
                            var staticLogFileNameConfig = m.Element(LogConstants.E_StaticLogFileName);
                            if (staticLogFileNameConfig != null)
                            {
                                staticLogFileName = staticLogFileNameConfig.Attribute(LogConstants.Value).Value;
                            }

                            var conversionPattern       = LogConstants.Config_ConversionPattern;
                            var conversionPatternConfig = m.Element(LogConstants.E_ConversionPattern);
                            if (conversionPatternConfig != null)
                            {
                                conversionPattern = conversionPatternConfig.Attribute(LogConstants.Value).Value;
                            }
                            LoadLog4NetConfig.LoadRollingFileAppender(name, appendToFile, datePattern, file, maximumFileSize, maxSizeRollBackups, staticLogFileName, conversionPattern);
                        }
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                throw new Exception(Constants.Error_Data_InitConfigFailed, ex);
            }
        }