本文整理汇总了C#中log4net.Layout.PatternLayout类的典型用法代码示例。如果您正苦于以下问题:C# PatternLayout类的具体用法?C# PatternLayout怎么用?C# PatternLayout使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PatternLayout类属于log4net.Layout命名空间,在下文中一共展示了PatternLayout类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Configure
public void Configure()
{
Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository();
hierarchy.Root.RemoveAllAppenders(); /*Remove any other appenders*/
FileAppender fileAppender = new FileAppender();
fileAppender.AppendToFile = true;
fileAppender.LockingModel = new FileAppender.MinimalLock();
fileAppender.File = _locationProvider.GetFilePath();
PatternLayout pl = new PatternLayout();
pl.ConversionPattern = "%d [%2%t] %-5p [%-10c] %m%n%n";
pl.ActivateOptions();
fileAppender.Layout = pl;
fileAppender.ActivateOptions();
ConsoleAppender consoleAppender = new ConsoleAppender();
consoleAppender.Layout = pl;
consoleAppender.ActivateOptions();
// log4net.Config.BasicConfigurator.Configure(fileAppender);
IAppender[] appenders = {fileAppender, consoleAppender};
log4net.Config.BasicConfigurator.Configure(appenders);
var log = LogManager.GetLogger(GetType());
log.Debug("Logging Configured");
}
示例2: CrearAppenderFichero
/// <summary>
/// Contiene la logica para crear un appender FICHERO
/// </summary>
/// <param name="nombreAppender">Nombre del appender</param>
/// <param name="nombreFichero">Nombre del fichero</param>
/// <param name="patronConversion"> Si se deja a null el valor por defecto es %d [%t] %-5p %c [%x] - %m%n </param>
/// <returns>Retorna el appender creado</returns>
public static IAppender CrearAppenderFichero(string nombreAppender, string nombreFichero, string patronConversion)
{
var appender = new FileAppender
{
Name = nombreAppender,
File = nombreFichero,
AppendToFile = true
};
var patronConversionAux = "%d [%t] %-5p %c [%x] - %m%n";
if(patronConversion != null && !patronConversion.Equals(string.Empty))
{
patronConversionAux = patronConversion;
}
var layout = new PatternLayout
{
ConversionPattern = patronConversionAux
};
layout.ActivateOptions();
appender.Layout = layout;
appender.ActivateOptions();
return appender;
}
示例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: Configure
/// <summary>
/// Configures the <see cref="FileLogger"/> logger adding the appenders to
/// the root repository.
/// </summary>
/// <remarks></remarks>
public void Configure() {
// create a new logger into the repository of the current assembly.
ILoggerRepository root_repository =
LogManager.GetRepository(Assembly.GetExecutingAssembly());
Logger nohros_file_logger =
root_repository.GetLogger("NohrosFileAppender") as Logger;
// create the layout and appender for log messages
PatternLayout layout = new PatternLayout();
layout.ConversionPattern = layout_pattern_;
layout.ActivateOptions();
FileAppender appender = new FileAppender();
appender.Name = "NohrosCommonFileAppender";
appender.File = log_file_path_;
appender.AppendToFile = true;
appender.Layout = layout;
appender.Threshold = Level.All;
appender.ActivateOptions();
// add the appender to the root repository
nohros_file_logger.Parent.AddAppender(appender);
root_repository.Configured = true;
logger = LogManager.GetLogger("NohrosFileLogger");
}
示例5: SimpleTest
public void SimpleTest()
{
container.AddComponent("component1", typeof(SimpleLoggingComponent));
SimpleLoggingComponent test = container["component1"] as SimpleLoggingComponent;
test.DoSomething();
String expectedLogOutput = String.Format("[INFO ] [{0}] - Hello world" + Environment.NewLine, typeof(SimpleLoggingComponent).FullName);
MemoryAppender memoryAppender = ((Hierarchy)LogManager.GetRepository()).Root.GetAppender("memory") as MemoryAppender;
TextWriter actualLogOutput = new StringWriter();
PatternLayout patternLayout = new PatternLayout("[%-5level] [%logger] - %message%newline");
patternLayout.Format(actualLogOutput, memoryAppender.GetEvents()[0]);
Assert.AreEqual(expectedLogOutput, actualLogOutput.ToString());
container.AddComponent("component2", typeof(SmtpServer));
ISmtpServer smtpServer = container["component2"] as ISmtpServer;
smtpServer.Start();
smtpServer.InternalSend("[email protected]", "[email protected]", "We're looking for a few good porgrammars.");
smtpServer.Stop();
expectedLogOutput = String.Format("[DEBUG] [Castle.Facilities.Logging.Tests.Classes.SmtpServer] - Stopped" + Environment.NewLine, typeof(SimpleLoggingComponent).FullName);
memoryAppender = ((Hierarchy)LogManager.GetRepository()).Root.GetAppender("memory") as MemoryAppender;
actualLogOutput = new StringWriter();
patternLayout = new PatternLayout("[%-5level] [%logger] - %message%newline");
Assert.AreEqual(memoryAppender.GetEvents().Length, 4);
patternLayout.Format(actualLogOutput, memoryAppender.GetEvents()[3]);
Assert.AreEqual(expectedLogOutput, actualLogOutput.ToString());
}
示例6: InitLogger
/// <summary>
/// Init log4net memoryAppender
/// http://dhvik.blogspot.com/2008/08/adding-appender-to-log4net-in-runtime.html
/// </summary>
void InitLogger()
{
//First create and configure the appender
this.memoryAppender = new MemoryAppender();
this.memoryAppender.Name = this.GetType().Name + "MemoryAppender";
PatternLayout layout = new PatternLayout();
layout.ConversionPattern = "%date [%thread] %-5level %logger - %message%newline";
layout.ActivateOptions();
this.memoryAppender.Layout = layout;
//Notify the appender on the configuration changes
this.memoryAppender.ActivateOptions();
//Get the logger repository hierarchy.
this.repository = (Hierarchy)LogManager.GetRepository();
//and add the appender to the root level
//of the logging hierarchy
this.repository.Root.AddAppender(memoryAppender);
//configure the logging at the root.
//this.repository.Root.Level = Level.Info;
//mark repository as configured and notify that is has changed.
this.repository.Configured = true;
this.repository.RaiseConfigurationChanged(EventArgs.Empty);
this.msgWriter = new StringWriter();
}
示例7: 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;
}
示例8: Log4NetConsoleFactory
public Log4NetConsoleFactory(LogLevel level)
{
var hierarchy = (Hierarchy)global::log4net.LogManager.GetRepository();
hierarchy.Root.RemoveAllAppenders();
var layout = new PatternLayout { ConversionPattern = "%utcdate{ISO8601} [%thread] %-3level %-8logger{1} - %message%newline" };
layout.ActivateOptions();
var appender = new ColoredConsoleAppender
{
Layout = layout,
Threshold = ToLog4NetLevel(level)
};
appender.AddMapping(new ColoredConsoleAppender.LevelColors { ForeColor = ColoredConsoleAppender.Colors.HighIntensity, Level = Level.Debug });
appender.AddMapping(new ColoredConsoleAppender.LevelColors { ForeColor = ColoredConsoleAppender.Colors.Cyan, Level = Level.Info });
appender.AddMapping(new ColoredConsoleAppender.LevelColors { ForeColor = ColoredConsoleAppender.Colors.White, BackColor = ColoredConsoleAppender.Colors.Yellow, Level = Level.Warn });
appender.AddMapping(new ColoredConsoleAppender.LevelColors { ForeColor = ColoredConsoleAppender.Colors.White, BackColor = ColoredConsoleAppender.Colors.Red, Level = Level.Error });
appender.AddMapping(new ColoredConsoleAppender.LevelColors { ForeColor = ColoredConsoleAppender.Colors.White, BackColor = ColoredConsoleAppender.Colors.Red, Level = Level.Fatal });
appender.ActivateOptions();
hierarchy.Root.AddAppender(appender);
hierarchy.Configured = true;
}
示例9: 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 =
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Tailviewer",
"Tailviewer.log"),
Layout = patternLayout,
MaxSizeRollBackups = 20,
MaximumFileSize = "1GB",
RollingStyle = RollingFileAppender.RollingMode.Size,
StaticLogFileName = false
};
fileAppender.ActivateOptions();
hierarchy.Root.AddAppender(fileAppender);
hierarchy.Root.Level = Level.Info;
hierarchy.Configured = true;
}
示例10: Initialize
public static void Initialize()
{
var hierarchy = (Hierarchy)LogManager.GetRepository();
var patternLayout = new PatternLayout();
patternLayout.ConversionPattern = "%date %-5level %logger - %message%newline";
patternLayout.ActivateOptions();
var roller = new RollingFileAppender();
roller.AppendToFile = false;
roller.File = @"Logs\EventLog.txt";
roller.Layout = patternLayout;
roller.MaxSizeRollBackups = 5;
roller.MaximumFileSize = "1GB";
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 = Level.Info;
hierarchy.Configured = true;
}
示例11: 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;
}
示例12: 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;
}
示例13: ConfigureLogging
public static void ConfigureLogging()
{
var layout = new PatternLayout
{
ConversionPattern = "%d [%t] %-5p %c [%x] - %m%n"
};
layout.ActivateOptions();
var consoleAppender = new ColoredConsoleAppender
{
Threshold = Level.Debug,
Layout = layout
};
consoleAppender.ActivateOptions();
var fileAppender = new RollingFileAppender
{
DatePattern = "yyyy-MM-dd'.txt'",
MaxFileSize = 10 * 1024 * 1024,
MaxSizeRollBackups = 10,
StaticLogFileName = false,
File = @"d:\logs\auth",
Layout = layout,
AppendToFile = true,
Threshold = Level.Debug,
};
#if DEBUG
fileAppender.File = @"log_";
#endif
fileAppender.ActivateOptions();
BasicConfigurator.Configure(fileAppender, consoleAppender);
}
示例14: 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;
}
示例15: Setup
/// <summary>
/// Setup Log4NET logger.
/// </summary>
internal static void Setup()
{
var hierarchy = (Hierarchy) LogManager.GetRepository();
var patternLayout = new PatternLayout
{
ConversionPattern = "%date [%thread] %-5level %logger - %message%newline"
};
patternLayout.ActivateOptions();
var roller = new FileAppender
{
AppendToFile = false,
File = @"AllureLog.txt",
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;
}