本文整理汇总了C#中log4net.Appender.RollingFileAppender类的典型用法代码示例。如果您正苦于以下问题:C# RollingFileAppender类的具体用法?C# RollingFileAppender怎么用?C# RollingFileAppender使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RollingFileAppender类属于log4net.Appender命名空间,在下文中一共展示了RollingFileAppender类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LogConfig
public LogConfig()
{
rootLevel = log4net.Core.Level.Debug;
patternLayout = new PatternLayout();
patternLayout.ConversionPattern = "%d %-7p [TID=%3t] %m%n";
consoleAppender = new ManagedColoredConsoleAppender();
consoleAppender.Layout = patternLayout;
consoleAppender.AddMapping(new ManagedColoredConsoleAppender.LevelColors() { ForeColor = ConsoleColor.Red, BackColor=ConsoleColor.White, Level = log4net.Core.Level.Fatal });
consoleAppender.AddMapping(new ManagedColoredConsoleAppender.LevelColors() { ForeColor = ConsoleColor.Red, Level = log4net.Core.Level.Error});
consoleAppender.AddMapping(new ManagedColoredConsoleAppender.LevelColors() { ForeColor = ConsoleColor.Yellow, Level = log4net.Core.Level.Warn });
consoleAppender.AddMapping(new ManagedColoredConsoleAppender.LevelColors() { ForeColor = ConsoleColor.Green, Level = log4net.Core.Level.Info});
consoleAppender.AddMapping(new ManagedColoredConsoleAppender.LevelColors() { ForeColor = ConsoleColor.White, Level = log4net.Core.Level.Debug});
consoleAppender.AddMapping(new ManagedColoredConsoleAppender.LevelColors() { ForeColor = ConsoleColor.Gray, Level = log4net.Core.Level.Verbose });
rollingAppender = new RollingFileAppender();
rollingAppender.Layout = patternLayout;
rollingAppender.MaxFileSize = 10 * 1048576;
rollingAppender.MaxSizeRollBackups = 20;
rollingAppender.AppendToFile = true;
rollingAppender.RollingStyle = RollingFileAppender.RollingMode.Size;
rollingAppender.StaticLogFileName = true;
rollingAppender.File = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Assembly.GetEntryAssembly().GetName().Name + ".log");
}
示例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: RegisterTypes
public static void RegisterTypes(IUnityContainer container)
{
var hierarchy = (Hierarchy)LogManager.GetRepository();
hierarchy.Root.RemoveAllAppenders();
hierarchy.Root.Level = Level.Debug;
hierarchy.RaiseConfigurationChanged(EventArgs.Empty);
FileAppender fileAppender = new RollingFileAppender();
fileAppender.AppendToFile = true;
fileAppender.LockingModel = new FileAppender.MinimalLock();
fileAppender.File = HttpContext.Current.Server.MapPath("~/TestHarness1.log.txt");
var patternLayout = new PatternLayout { ConversionPattern = "%d [%2%t] %-5p [%-10c] %m%n%n" };
patternLayout.ActivateOptions();
fileAppender.Layout = patternLayout;
fileAppender.ActivateOptions();
BasicConfigurator.Configure(fileAppender);
var logger = LogManager.GetLogger(typeof(IServiceBus));
container.RegisterInstance<ILog>(logger, new ContainerControlledLifetimeManager());
var ftpClient = new FtpQueueClient();
ftpClient.ConnectAsync(new Uri("ftp://ftp.jdibble.co.uk/site1/Personal/service-bus-ftp/queue"), new NetworkCredential("jdibble-001", "jli798ik")).Wait();
container.RegisterInstance<IFtpQueueClient>(ftpClient, new ContainerControlledLifetimeManager());
container.RegisterType<IQueueManager, FtpQueueManager>(new ContainerControlledLifetimeManager());
container.RegisterType<SharedMessageHandler>();
var messageDictionary = new MessageTypeDictionary
{
{ ServiceBus.Messaging.MessageExtensions.MessageTypeSignature<SharedMessage>(), typeof(SharedMessage) },
{ ServiceBus.Messaging.MessageExtensions.MessageTypeSignature<NonSharedMessage>(), typeof(NonSharedMessage) },
{ ServiceBus.Messaging.MessageExtensions.MessageTypeSignature<SharedEvent>(), typeof(SharedEvent) }
};
container.RegisterInstance<IMessageSerialiser>(new JsonMessageSerialiser(messageDictionary), new ContainerControlledLifetimeManager());
var serviceBus =
ServiceBusBuilder.Configure()
.WithLogger(container.Resolve<ILog>())
.WithHostAddress(new Uri("http://servicebus-ftp.jdibble.co.uk"))
.WithHttpTransport(new JsonMessageSerialiser(messageDictionary))
.AsMvcServiceBus(RouteTable.Routes, container.Resolve<IQueueManager>())
.Build()
.WithMessageHandler(container.Resolve<SharedMessageHandler>())
.Subscribe(container.Resolve<SharedEventHandler>())
.WithPeerAsync(new Peer(new Uri("http://servicebus-ftp2.jdibble.co.uk"))).Result;
serviceBus.WithPeerAsync(new Peer(new Uri("http://servicebus.jdibble.co.uk")));
serviceBus.WithPeerAsync(new Peer(new Uri("http://servicebus2.jdibble.co.uk")));
container.RegisterInstance(serviceBus, new ContainerControlledLifetimeManager());
container.RegisterType<ServiceBusHub>(new ContainerControlledLifetimeManager());
}
示例4: Setup
/// <summary>
/// Configures the log4net environment
/// </summary>
private void Setup(Level logLevel)
{
Directory.CreateDirectory(_logFolder);
var hierarchy = (Hierarchy)LogManager.GetRepository();
// Log to a file
var roller = new RollingFileAppender();
roller.AppendToFile = false;
roller.File = _logFile;
roller.Layout = new PatternLayout("%date %type.%method [%-5level] - %message%newline");
roller.MaxSizeRollBackups = 5;
roller.RollingStyle = RollingFileAppender.RollingMode.Size;
roller.StaticLogFileName = true;
roller.ActivateOptions();
hierarchy.Root.AddAppender(roller);
// Log to the visual studio console
var appender = new TraceAppender();
appender.ActivateOptions();
appender.Layout = new PatternLayout("%method (%line) %date [%-5level] - %message%newline");
hierarchy.Root.AddAppender(appender);
hierarchy.Root.Level = logLevel;
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: 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
}
}
示例7: InitLog
//configure log4Net via code instead of xml
public static void InitLog(string completeLogFile)
{
_filePath = completeLogFile;
var hierarchy = (log4net.Repository.Hierarchy.Hierarchy)LogManager.GetRepository();
hierarchy.Root.RemoveAllAppenders();
var pl = new log4net.Layout.PatternLayout { ConversionPattern = DefaultConversionPatern };
pl.ActivateOptions();
var fileAppender = new RollingFileAppender()
{
AppendToFile = true,
LockingModel = new FileAppender.MinimalLock(),
File = _filePath,
Layout = pl,
};
fileAppender.MaxFileSize = 10 * 1024 * 1024;
fileAppender.RollingStyle = RollingFileAppender.RollingMode.Size;
fileAppender.MaxSizeRollBackups = 5;
fileAppender.ActivateOptions();
BasicConfigurator.Configure(fileAppender);
_logger = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
}
示例8: SetupLogger
/// <summary>
/// Setups the logger configuration. Can be used instead of loading log4net.config file
/// </summary>
public static void SetupLogger()
{
Hierarchy hierarchy = (Hierarchy) LogManager.GetRepository();
PatternLayout patternLayout = new DynamicPatternLayout();
patternLayout.ConversionPattern = "%date{dd MMM yyyy HH:mm:ss} [%thread] %level - %message %exception %newline";
patternLayout.ActivateOptions();
RollingFileAppender roller = new RollingFileAppender
{
// appends the log into same file
AppendToFile = true,
File = @"DeployLogs\\Deploylog.log",
Layout = patternLayout,
MaxSizeRollBackups = 1000,
RollingStyle = RollingFileAppender.RollingMode.Date,
StaticLogFileName = false
};
roller.ActivateOptions();
hierarchy.Root.AddAppender(roller);
MemoryAppender memoryAppender = new MemoryAppender();
memoryAppender.ActivateOptions();
hierarchy.Root.AddAppender(memoryAppender);
hierarchy.Root.Level = Level.All;
hierarchy.Configured = true;
}
示例9: Setup
public void Setup()
{
var applicationDataDirectory =
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
"PCoMD", "Log");
LogFilePath = Path.Combine(applicationDataDirectory, "PCoMD.xml");
var hierarchy = (Hierarchy) LogManager.GetRepository();
var patternLayout = new XmlLayoutSchemaLog4j();
patternLayout.LocationInfo = true;
patternLayout.ActivateOptions();
var roller = new RollingFileAppender
{
AppendToFile = true,
MaximumFileSize = "2MB",
File = LogFilePath,
PreserveLogFileNameExtension = true,
MaxSizeRollBackups = 10,
RollingStyle = RollingFileAppender.RollingMode.Size,
Layout = patternLayout
};
roller.ActivateOptions();
hierarchy.Root.AddAppender(roller);
var memory = new MemoryAppender();
memory.ActivateOptions();
hierarchy.Root.AddAppender(memory);
hierarchy.Root.Level = Level.Info;
hierarchy.Configured = true;
XmlConfigurator.Configure(hierarchy);
}
示例10: 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;
}
示例11: 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();
}
示例12: 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;
}
示例13: 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;
}
示例14: 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);
}
示例15: 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;
}