本文整理汇总了C#中log4net.Appender.RollingFileAppender.ActivateOptions方法的典型用法代码示例。如果您正苦于以下问题:C# RollingFileAppender.ActivateOptions方法的具体用法?C# RollingFileAppender.ActivateOptions怎么用?C# RollingFileAppender.ActivateOptions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类log4net.Appender.RollingFileAppender
的用法示例。
在下文中一共展示了RollingFileAppender.ActivateOptions方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Log4NetAdapter
/// <summary>
/// 初始化一个<see cref="Log4NetAdapter"/>类型的新实例
/// </summary>k
public Log4NetAdapter()
{
// var configFile = Path.Combine(ConfigPath, FileName);
// if (File.Exists(configFile))
// {
// XmlConfigurator.ConfigureAndWatch(new FileInfo(configFile));
// return;
// }
var appender = new RollingFileAppender
{
Name = "root",
File = "logs\\log_",
AppendToFile = true,
LockingModel = new FileAppender.MinimalLock(),
RollingStyle = RollingFileAppender.RollingMode.Date,
DatePattern = "yyyyMMdd-HH\".log\"",
StaticLogFileName = false,
MaxSizeRollBackups = 10,
Layout = new PatternLayout("[%d{yyyy-MM-dd HH:mm:ss.fff}] %-5p %c %t %w %n%m%n")
//Layout = new PatternLayout("[%d [%t] %-5p %c [%x] - %m%n]")
};
appender.ClearFilters();
appender.AddFilter(new LevelRangeFilter
{
LevelMin = Level.Debug,
LevelMax = Level.Fatal
});
BasicConfigurator.Configure(appender);
appender.ActivateOptions();
}
示例2: Setup
public static void Setup(string path)
{
var hierarchy = (Hierarchy)LogManager.GetRepository();
var patternLayout = new PatternLayout();
patternLayout.ConversionPattern = "%date [%thread] %-5level %logger - %message%newline";
// patternLayout.ConversionPattern = "%date [%thread] %-5level %logger - %message%newline";
patternLayout.ActivateOptions();
var roller = new RollingFileAppender();
roller.AppendToFile = true;
roller.File = path;
roller.Layout = patternLayout;
roller.MaxSizeRollBackups = 5;
roller.MaximumFileSize = "2MB";
roller.RollingStyle = RollingFileAppender.RollingMode.Size;
roller.StaticLogFileName = true;
roller.ActivateOptions();
hierarchy.Root.AddAppender(roller);
var memory = new MemoryAppender();
memory.ActivateOptions();
hierarchy.Root.AddAppender(memory);
hierarchy.Root.Level = Level.Info;
hierarchy.Configured = true;
}
示例3: SetupLoggers
private static void SetupLoggers()
{
var hierarchy = (Hierarchy)LogManager.GetRepository();
var patternLayout = new PatternLayout
{
ConversionPattern = "%date [%thread] %-5level %logger - %message%newline"
};
patternLayout.ActivateOptions();
var fileAppender = new RollingFileAppender
{
AppendToFile = false,
File = Constants.InstallationLog,
Layout = patternLayout,
MaxSizeRollBackups = 3,
MaximumFileSize = "1GB",
RollingStyle = RollingFileAppender.RollingMode.Size,
StaticLogFileName = false
};
fileAppender.ActivateOptions();
hierarchy.Root.AddAppender(fileAppender);
hierarchy.Root.Level = Level.Info;
hierarchy.Configured = true;
}
示例4: Setup
public static void Setup()
{
Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository();
var patternLayout = new PatternLayout();
patternLayout.ConversionPattern = "%date{yyyy-MM-dd HH:mm:ss.fff} %-6level %message%newline";
patternLayout.ActivateOptions();
var roller = new RollingFileAppender();
roller.AppendToFile = true;
roller.File = LostKeysUnited.Location.FullName + ".log";
roller.Layout = patternLayout;
roller.MaxSizeRollBackups = 5;
roller.MaximumFileSize = "1GB";
roller.RollingStyle = RollingFileAppender.RollingMode.Size;
roller.StaticLogFileName = true;
roller.ActivateOptions();
hierarchy.Root.AddAppender(roller);
#if DEBUG
hierarchy.Root.Level = Level.Debug;
#else
hierarchy.Root.Level = Level.Error;
#endif
hierarchy.Configured = true;
}
示例5: Log4NetLogFactory
public Log4NetLogFactory(LogFileSettings settings)
{
var patternLayout = new log4net.Layout.PatternLayout(
"%date [%thread] %level %logger - %message%newline");
patternLayout.ActivateOptions();
RollingFileAppender appender
= new RollingFileAppender
{
Name = "rolling-appender",
File = Path.Combine(settings.DirectoryPath, settings.NamePrefix + ".log"),
AppendToFile = true,
MaxSizeRollBackups = 10,
RollingStyle = RollingFileAppender.RollingMode.Date,
Layout = patternLayout,
LockingModel = new FileAppender.MinimalLock()
};
appender.ActivateOptions();
log4net.Config.BasicConfigurator.Configure(appender);
Hierarchy h = (Hierarchy)LogManager.GetRepository();
Logger rootLogger = h.Root;
rootLogger.Level = h.LevelMap[ConvertLogLevel(settings.Level).ToString().ToUpper()];
}
示例6: Logger
static Logger()
{
Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository();
TraceAppender tracer = new TraceAppender();
PatternLayout patternLayout = new PatternLayout();
patternLayout.ConversionPattern = LOG_PATTERN;
patternLayout.ActivateOptions();
tracer.Layout = patternLayout;
tracer.ActivateOptions();
hierarchy.Root.AddAppender(tracer);
RollingFileAppender roller = new RollingFileAppender();
roller.Layout = patternLayout;
roller.AppendToFile = true;
roller.RollingStyle = RollingFileAppender.RollingMode.Size;
roller.MaxSizeRollBackups = 4;
roller.MaximumFileSize = "32768KB";
roller.StaticLogFileName = true;
roller.File = "log\\Log.log";
roller.ActivateOptions();
hierarchy.Root.AddAppender(roller);
hierarchy.Root.Level = Level.All;
hierarchy.Configured = true;
}
示例7: Configure
public static void Configure(string appfolder, string logFile)
{
bool isConfigured = _log.Logger.Repository.Configured;
if (!isConfigured)
{
// Setup RollingFileAppender
var fileAppender = new RollingFileAppender
{
Layout =
new PatternLayout(
"%d %level [%type{1}] - %m%n"),
MaximumFileSize = "1000KB",
MaxSizeRollBackups = 10,
RollingStyle = RollingFileAppender.RollingMode.Composite,
AppendToFile = true,
File = logFile,
ImmediateFlush = true,
LockingModel = new FileAppender.MinimalLock(),
Name = "XXXRollingFileAppender",
Threshold = log4net.Core.Level.All
};
fileAppender.ActivateOptions(); // IMPORTANT, creates the file
BasicConfigurator.Configure(fileAppender);
#if DEBUG
// Setup TraceAppender
TraceAppender ta = new TraceAppender();
ta.Layout = new PatternLayout("%d [%t]%-5p %c [%x] - %m%n");
BasicConfigurator.Configure(ta);
#endif
}
}
示例8: Logger
static Logger()
{
var hierarchy = (Hierarchy)LogManager.GetRepository();
var tracer = new TraceAppender();
var patternLayout = new PatternLayout {ConversionPattern = LOG_PATTERN};
patternLayout.ActivateOptions();
tracer.Layout = patternLayout;
tracer.ActivateOptions();
hierarchy.Root.AddAppender(tracer);
var roller = new RollingFileAppender
{
Layout = patternLayout,
AppendToFile = true,
RollingStyle = RollingFileAppender.RollingMode.Size,
MaxSizeRollBackups = 4,
MaximumFileSize = "10240KB",
StaticLogFileName = true,
File = FilePath + @"\f1speed-log.txt"
};
roller.ActivateOptions();
hierarchy.Root.AddAppender(roller);
hierarchy.Root.Level = Level.Debug;
hierarchy.Configured = true;
}
示例9: InitLog4net
private static void InitLog4net()
{
Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository();
PatternLayout patternLayout = new PatternLayout();
patternLayout.ConversionPattern = "[%date] %-5level [%thread] %property{user} - %message%exception%n";
patternLayout.ActivateOptions();
RollingFileAppender roller = new RollingFileAppender();
roller.AppendToFile = true;
roller.File = @"logs\";
roller.Layout = patternLayout;
roller.MaxSizeRollBackups = 100;
roller.MaximumFileSize = "10MB";
roller.RollingStyle = RollingFileAppender.RollingMode.Date;
roller.DatePattern = "yyyyMMdd'.log'";
roller.StaticLogFileName = false;
roller.ActivateOptions();
hierarchy.Root.AddAppender(roller);
hierarchy.Root.Level = Level.All;
hierarchy.Configured = true;
log4net.GlobalContext.Properties["user"] = new Log4NetUserNameProvider();
}
示例10: CLogger
/// <summary>
/// constructor that initialize logger name, file name and log level
/// </summary>
public CLogger(string sLoggerName, string sFilename, int iLogLevel)
{
ILog oLogger = LogManager.GetLogger(sLoggerName);
string sLogFileName = string.Empty;
sLogFileName = GetLogFileName(sFilename);
m_oFPLogger = (log4net.Repository.Hierarchy.Logger)oLogger.Logger;
log4net.Appender.RollingFileAppender oFPAppender = new RollingFileAppender();
oFPAppender.File = sLogFileName;
oFPAppender.MaxSizeRollBackups = 100;
oFPAppender.MaximumFileSize = "1MB";
oFPAppender.RollingStyle = RollingFileAppender.RollingMode.Size;
oFPAppender.StaticLogFileName = true;
oFPAppender.AppendToFile = true;
log4net.Layout.PatternLayout layout = new log4net.Layout.PatternLayout();
layout.ConversionPattern = "%d %-5p - %m%n%exception";
layout.ActivateOptions();
oFPAppender.Layout = layout;
oFPAppender.ActivateOptions();
/** Programmatically configuration will not work it it is not set true**/
m_oFPLogger.Hierarchy.Configured = true;
try
{
m_oFPLogger.AddAppender(oFPAppender);
}
catch (Exception ex)
{
throw new Exception("Failed to Add Appender", ex);
}
m_oFPLogger.Hierarchy.Root.Level = m_oFPLogger.Hierarchy.LevelMap[GetLogLevel(iLogLevel)];
oLogger = null;
}
示例11: DefaultLogWrapper
public DefaultLogWrapper(string logname, IConfig config)
{
this.logname = logname;
Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository();
hierarchy.Clear();
TraceAppender tracer = new TraceAppender();
PatternLayout patternLayout = new PatternLayout();
patternLayout.ConversionPattern = "%t (%-5level) - %m%n";
patternLayout.ActivateOptions();
tracer.Layout = patternLayout;
tracer.ActivateOptions();
hierarchy.Root.AddAppender(tracer);
RollingFileAppender roller = new RollingFileAppender();
roller.Layout = patternLayout;
roller.AppendToFile = true;
roller.RollingStyle = RollingFileAppender.RollingMode.Size;
roller.MaxSizeRollBackups = 4;
roller.MaximumFileSize = "100KB";
roller.StaticLogFileName = true;
roller.File = Path.Combine(config.IndexFolder, "totalrecall-" + this.logname + ".log");
roller.ActivateOptions();
hierarchy.Root.AddAppender(roller);
hierarchy.Root.Level = Level.All;
hierarchy.Configured = true;
}
示例12: Configure
public static void Configure()
{
var hierarchy = (Hierarchy)LogManager.GetRepository();
hierarchy.Root.RemoveAllAppenders();
// see http://logging.apache.org/log4net/release/sdk/log4net.Layout.PatternLayout.html
var layout = new PatternLayout
{
ConversionPattern = "%date{dd-MMM-yyyy HH:mm:ss} %-5level %message%n%exception%n"
};
var fileAppender = new RollingFileAppender
{
Layout = layout,
AppendToFile = true,
File = "log.txt",
LockingModel = new FileAppender.MinimalLock(),
};
var consoleAppender = new ConsoleAppender
{
Layout = layout,
};
layout.ActivateOptions();
fileAppender.ActivateOptions();
log4net.Config.BasicConfigurator.Configure(fileAppender);
consoleAppender.ActivateOptions();
log4net.Config.BasicConfigurator.Configure(consoleAppender);
}
示例13: Logging
public Logging(string sFileName, string sLocation, bool bUseLogging)
{
m_sFileName = sFileName;
if (!bUseLogging) return;
if (sLocation.Length > 0)
if (sLocation[sLocation.Length - 1] != '\\')
sLocation += "\\";
m_RFL = new log4net.Appender.RollingFileAppender();
m_RFL.File = sLocation + m_sFileName + m_sFileExt;
m_RFL.StaticLogFileName = true;
m_RFL.AppendToFile = true;
m_RFL.RollingStyle = log4net.Appender.RollingFileAppender.RollingMode.Size;
m_RFL.MaximumFileSize = "10mb";
m_RFL.MaxSizeRollBackups = 2;
m_RFL.Threshold = log4net.Core.Level.All;
//m_RFL.CountDirection = 1;
//m_RFL.DatePattern = "HH:MM::SS";
log4net.Layout.PatternLayout layout = new log4net.Layout.PatternLayout("%message%newline");
layout.ActivateOptions();
log4net.Filter.LevelRangeFilter filter = new log4net.Filter.LevelRangeFilter();
filter.LevelMax = log4net.Core.Level.Emergency;
filter.LevelMin = log4net.Core.Level.All;
m_RFL.AddFilter(filter);
m_RFL.Layout = layout;
m_RFL.ActivateOptions();
log4net.Config.BasicConfigurator.Configure(m_RFL);
// Set up
Log(Logging.LOGTYPE.ERROR, "Start logging...");
}
示例14: Setup
public static void Setup()
{
Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository();
PatternLayout patternLayout = new PatternLayout();
patternLayout.ConversionPattern = "%date{dd/MM/yyyy hh:mm:ss.fff tt} | %logger[%method:%line] %level - %message%newline%exception";
patternLayout.ActivateOptions();
RollingFileAppender roller = new RollingFileAppender();
roller.AppendToFile = false;
roller.Encoding = Encoding.UTF8;
roller.File = DataEx.log_Events;
roller.Layout = patternLayout;
roller.MaxSizeRollBackups = 5;
roller.MaximumFileSize = "5MB";
roller.RollingStyle = RollingFileAppender.RollingMode.Size;
roller.StaticLogFileName = true;
roller.ActivateOptions();
hierarchy.Root.AddAppender(roller);
MemoryAppender memory = new MemoryAppender();
memory.ActivateOptions();
hierarchy.Root.AddAppender(memory);
hierarchy.Root.Level = (bool)App.Current.Properties["Troubleshooting"] ? Level.Debug : Level.Info;
hierarchy.Configured = true;
doFirstEntry();
}
示例15: ConfigurePlugin
protected override void ConfigurePlugin(PluginConfiguration pluginConfiguration, PluginInspector pluginInspector)
{
_moduleName = pluginConfiguration.ModuleName;
BasicConfigurator.Configure();
var defaultPattern = new PatternLayout { ConversionPattern = LogPattern };
defaultPattern.ActivateOptions();
var rollingFileAppender = new RollingFileAppender
{
Name = "RollingFileAppender",
File = "Log/" + _moduleName + ".log",
AppendToFile = true,
RollingStyle = RollingFileAppender.RollingMode.Size,
MaxSizeRollBackups = 15,
MaximumFileSize = "100MB",
StaticLogFileName = true,
Layout = defaultPattern
};
rollingFileAppender.ActivateOptions();
rollingFileAppender.ImmediateFlush = true;
rollingFileAppender.LockingModel= new FileAppender.InterProcessLock();
var root = ((Hierarchy)global::log4net.LogManager.GetRepository()).Root;
root.AddAppender(rollingFileAppender);
root.Level = Level.Debug;
root.Repository.Configured = true;
}