- var cr = RegistrationBuilder.ForType(t).CreateRegistration();
-
- The full builder syntax is supported.
-
- var cr = RegistrationBuilder.ForType(t).Named("foo").ExternallyOwned().CreateRegistration();
-
-
- var registration = RegistrationBuilder.ForType<Foo>().CreateRegistration();
-
-
- var builder = new ContainerBuilder();
-
- builder.RegisterType<Logger>()
- .As<ILogger>()
- .SingleInstance();
-
- builder.Register(c => new MessageHandler(c.Resolve<ILogger>()));
-
- var container = builder.Build();
- // resolve components from container...
-
-
- IContainer cr = // ...
- using (var lifetime = cr.BeginLifetimeScope(builder => {
- builder.RegisterType<Foo>();
- builder.RegisterType<Bar>().As<IBar>(); })
- {
- var foo = lifetime.Resolve<Foo>();
- }
-
-
- IContainer cr = // ...
- using (var lifetime = cr.BeginLifetimeScope("unitOfWork", builder => {
- builder.RegisterType<Foo>();
- builder.RegisterType<Bar>().As<IBar>(); })
- {
- var foo = lifetime.Resolve<Foo>();
- }
-
-
- public class Manager
- {
- public Manager([KeyFilter("Manager")] ILogger logger)
- {
- // ...
- }
- }
-
-
- public class SolutionExplorer
- {
- public SolutionExplorer(
- [KeyFilter("Solution")] IEnumerable<IAdapter> adapters,
- [KeyFilter("Solution")] ILogger logger)
- {
- this.Adapters = adapters.ToList();
- this.Logger = logger;
- }
- }
-
-
- var builder = new ContainerBuilder();
-
- // Register the components getting filtered with keys
- builder.RegisterType<ConsoleLogger>().Keyed<ILogger>("Solution");
- builder.RegisterType<FileLogger>().Keyed<ILogger>("Other");
-
- // Attach the filtering behavior to the component with the constructor
- builder.RegisterType<SolutionExplorer>().WithAttributeFiltering();
-
- var container = builder.Build();
-
- // The resolved instance will have the appropriate services in place
- var explorer = container.Resolve<SolutionExplorer>();
-
-
- public class Manager
- {
- public Manager([MetadataFilter("LoggerName", "Manager")] ILogger logger)
- {
- // ...
- }
- }
-
-
- public class SolutionExplorer
- {
- public SolutionExplorer(
- [MetadataFilter("Target", "Solution")] IEnumerable<IAdapter> adapters,
- [MetadataFilter("LoggerName", "Solution")] ILogger logger)
- {
- this.Adapters = adapters.ToList();
- this.Logger = logger;
- }
- }
-
-
- var builder = new ContainerBuilder();
-
- // Attach metadata to the components getting filtered
- builder.RegisterType<ConsoleLogger>().WithMetadata("LoggerName", "Solution").As<ILogger>();
- builder.RegisterType<FileLogger>().WithMetadata("LoggerName", "Other").As<ILogger>();
-
- // Attach the filtering behavior to the component with the constructor
- builder.RegisterType<SolutionExplorer>().WithAttributeFiltering();
-
- var container = builder.Build();
-
- // The resolved instance will have the appropriate services in place
- var explorer = container.Resolve<SolutionExplorer>();
-
-
- IIndex<AccountType, IRenderer> accountRenderers = // ...
- var renderer = accountRenderers[AccountType.User];
-
-
- public class D : IService, IDisposable
- {
- // ...
- }
-
- The dependent component C can dispose of the D instance whenever required by taking a dependency on
-
- public class C
- {
- IService _service;
-
- public C(Owned<IService> service)
- {
- _service = service;
- }
-
- void DoWork()
- {
- _service.Value.DoSomething();
- }
-
- void OnFinished()
- {
- _service.Dispose();
- }
- }
-
- In general, rather than depending on Resolve() for interfaces that have a single contravariant ('in') parameter.
-
- interface IHandler<in TCommand>
- {
- void Handle(TCommand command);
- }
-
- class Command { }
-
- class DerivedCommand : Command { }
-
- class CommandHandler : IHandler<Command> { ... }
-
- var builder = new ContainerBuilder();
- builder.RegisterSource(new ContravariantRegistrationSource());
- builder.RegisterType<CommandHandler>();
- var container = builder.Build();
- // Source enables this line, even though IHandler<Command> is the
- // actual registered type.
- var handler = container.Resolve<IHandler<DerivedCommand>>();
- handler.Handle(new DerivedCommand());
-
-
- // See ContainerBuilder for the definition of the builder variable
- using (var container = builder.Build())
- {
- var program = container.Resolve<Program>();
- program.Run();
- }
-
-
- // See IContainer for definition of the container variable
- using (var requestScope = container.BeginLifetimeScope())
- {
- // Note that handler is resolved from requestScope, not
- // from the container:
-
- var handler = requestScope.Resolve<IRequestHandler>();
- handler.Handle(request);
-
- // When requestScope is disposed, all resources used in processing
- // the request will be released.
- }
-
- OnActivated() event handler instead.
-
- public class DataAccessModule : Module
- {
- public string ConnectionString { get; set; }
-
- public override void Load(ContainerBuilder moduleBuilder)
- {
- moduleBuilder.RegisterGeneric(typeof(MyRepository<>))
- .As(typeof(IRepository<>))
- .InstancePerMatchingLifetimeScope(WebLifetime.Request);
-
- moduleBuilder.Register(c => new MyDbConnection(ConnectionString))
- .As<IDbConnection>()
- .InstancePerMatchingLifetimeScope(WebLifetime.Request);
- }
- }
-
- Using the module...
-
- var builder = new ContainerBuilder();
- builder.RegisterModule(new DataAccessModule { ConnectionString = "..." });
- var container = builder.Build();
- var customers = container.Resolve<IRepository<Customer>>();
-
-
- public class MyComponent
- {
- public MyComponent(int amount) { ... }
- }
-
-
- var builder = new ContainerBuilder();
- builder.RegisterType<MyComponent>();
- var container = builder.Build();
- var myComponent = container.Resolve<MyComponent>(new NamedParameter("amount", 123));
-
-
- builder.Register((c, p) => new FtpClient(p.Named<string>("server")));
-
- These parameters can be provided at resolution time:
-
- container.Resolve<FtpClient>(new NamedParameter("server", "ftp.example.com"));
-
- Alternatively, the parameters can be provided via a Generated Factory - http://code.google.com/p/autofac/wiki/DelegateFactories.
-
- public class MyComponent
- {
- public MyComponent(int amount) { ... }
- }
-
-
- var builder = new ContainerBuilder();
- builder.RegisterType<MyComponent>();
- var container = builder.Build();
- var myComponent = container.Resolve<MyComponent>(new PositionalParameter(0, 123));
-
- instance.GetType()).As<T> part.
-
-
- public class MyComponent
- {
- public MyComponent(int amount) { ... }
- }
-
-
- var builder = new ContainerBuilder();
- builder.RegisterType<MyComponent>();
- var container = builder.Build();
- var myComponent = container.Resolve<MyComponent>(new TypedParameter(typeof(int), 123));
-
-
- var cr = RegistrationBuilder.ForType(t).CreateRegistration();
-
- The full builder syntax is supported.
-
- var cr = RegistrationBuilder.ForType(t).Named("foo").ExternallyOwned().CreateRegistration();
-
-
- var registration = RegistrationBuilder.ForType<Foo>().CreateRegistration();
-
-
- var builder = new ContainerBuilder();
-
- builder.RegisterType<Logger>()
- .As<ILogger>()
- .SingleInstance();
-
- builder.Register(c => new MessageHandler(c.Resolve<ILogger>()));
-
- var container = builder.Build();
- // resolve components from container...
-
-
- IContainer cr = // ...
- using (var lifetime = cr.BeginLifetimeScope(builder => {
- builder.RegisterType<Foo>();
- builder.RegisterType<Bar>().As<IBar>(); })
- {
- var foo = lifetime.Resolve<Foo>();
- }
-
-
- IContainer cr = // ...
- using (var lifetime = cr.BeginLifetimeScope("unitOfWork", builder => {
- builder.RegisterType<Foo>();
- builder.RegisterType<Bar>().As<IBar>(); })
- {
- var foo = lifetime.Resolve<Foo>();
- }
-
-
- public class Manager
- {
- public Manager([KeyFilter("Manager")] ILogger logger)
- {
- // ...
- }
- }
-
-
- public class SolutionExplorer
- {
- public SolutionExplorer(
- [KeyFilter("Solution")] IEnumerable<IAdapter> adapters,
- [KeyFilter("Solution")] ILogger logger)
- {
- this.Adapters = adapters.ToList();
- this.Logger = logger;
- }
- }
-
-
- var builder = new ContainerBuilder();
-
- // Register the components getting filtered with keys
- builder.RegisterType<ConsoleLogger>().Keyed<ILogger>("Solution");
- builder.RegisterType<FileLogger>().Keyed<ILogger>("Other");
-
- // Attach the filtering behavior to the component with the constructor
- builder.RegisterType<SolutionExplorer>().WithAttributeFiltering();
-
- var container = builder.Build();
-
- // The resolved instance will have the appropriate services in place
- var explorer = container.Resolve<SolutionExplorer>();
-
-
- public class Manager
- {
- public Manager([MetadataFilter("LoggerName", "Manager")] ILogger logger)
- {
- // ...
- }
- }
-
-
- public class SolutionExplorer
- {
- public SolutionExplorer(
- [MetadataFilter("Target", "Solution")] IEnumerable<IAdapter> adapters,
- [MetadataFilter("LoggerName", "Solution")] ILogger logger)
- {
- this.Adapters = adapters.ToList();
- this.Logger = logger;
- }
- }
-
-
- var builder = new ContainerBuilder();
-
- // Attach metadata to the components getting filtered
- builder.RegisterType<ConsoleLogger>().WithMetadata("LoggerName", "Solution").As<ILogger>();
- builder.RegisterType<FileLogger>().WithMetadata("LoggerName", "Other").As<ILogger>();
-
- // Attach the filtering behavior to the component with the constructor
- builder.RegisterType<SolutionExplorer>().WithAttributeFiltering();
-
- var container = builder.Build();
-
- // The resolved instance will have the appropriate services in place
- var explorer = container.Resolve<SolutionExplorer>();
-
-
- IIndex<AccountType, IRenderer> accountRenderers = // ...
- var renderer = accountRenderers[AccountType.User];
-
-
- public class D : IService, IDisposable
- {
- // ...
- }
-
- The dependent component C can dispose of the D instance whenever required by taking a dependency on
-
- public class C
- {
- IService _service;
-
- public C(Owned<IService> service)
- {
- _service = service;
- }
-
- void DoWork()
- {
- _service.Value.DoSomething();
- }
-
- void OnFinished()
- {
- _service.Dispose();
- }
- }
-
- In general, rather than depending on Resolve() for interfaces that have a single contravariant ('in') parameter.
-
- interface IHandler<in TCommand>
- {
- void Handle(TCommand command);
- }
-
- class Command { }
-
- class DerivedCommand : Command { }
-
- class CommandHandler : IHandler<Command> { ... }
-
- var builder = new ContainerBuilder();
- builder.RegisterSource(new ContravariantRegistrationSource());
- builder.RegisterType<CommandHandler>();
- var container = builder.Build();
- // Source enables this line, even though IHandler<Command> is the
- // actual registered type.
- var handler = container.Resolve<IHandler<DerivedCommand>>();
- handler.Handle(new DerivedCommand());
-
-
- // See ContainerBuilder for the definition of the builder variable
- using (var container = builder.Build())
- {
- var program = container.Resolve<Program>();
- program.Run();
- }
-
-
- // See IContainer for definition of the container variable
- using (var requestScope = container.BeginLifetimeScope())
- {
- // Note that handler is resolved from requestScope, not
- // from the container:
-
- var handler = requestScope.Resolve<IRequestHandler>();
- handler.Handle(request);
-
- // When requestScope is disposed, all resources used in processing
- // the request will be released.
- }
-
- OnActivated() event handler instead.
-
- public class DataAccessModule : Module
- {
- public string ConnectionString { get; set; }
-
- public override void Load(ContainerBuilder moduleBuilder)
- {
- moduleBuilder.RegisterGeneric(typeof(MyRepository<>))
- .As(typeof(IRepository<>))
- .InstancePerMatchingLifetimeScope(WebLifetime.Request);
-
- moduleBuilder.Register(c => new MyDbConnection(ConnectionString))
- .As<IDbConnection>()
- .InstancePerMatchingLifetimeScope(WebLifetime.Request);
- }
- }
-
- Using the module...
-
- var builder = new ContainerBuilder();
- builder.RegisterModule(new DataAccessModule { ConnectionString = "..." });
- var container = builder.Build();
- var customers = container.Resolve<IRepository<Customer>>();
-
-
- public class MyComponent
- {
- public MyComponent(int amount) { ... }
- }
-
-
- var builder = new ContainerBuilder();
- builder.RegisterType<MyComponent>();
- var container = builder.Build();
- var myComponent = container.Resolve<MyComponent>(new NamedParameter("amount", 123));
-
-
- builder.Register((c, p) => new FtpClient(p.Named<string>("server")));
-
- These parameters can be provided at resolution time:
-
- container.Resolve<FtpClient>(new NamedParameter("server", "ftp.example.com"));
-
- Alternatively, the parameters can be provided via a Generated Factory - http://code.google.com/p/autofac/wiki/DelegateFactories.
-
- public class MyComponent
- {
- public MyComponent(int amount) { ... }
- }
-
-
- var builder = new ContainerBuilder();
- builder.RegisterType<MyComponent>();
- var container = builder.Build();
- var myComponent = container.Resolve<MyComponent>(new PositionalParameter(0, 123));
-
- instance.GetType()).As<T> part.
-
-
- public class MyComponent
- {
- public MyComponent(int amount) { ... }
- }
-
-
- var builder = new ContainerBuilder();
- builder.RegisterType<MyComponent>();
- var container = builder.Build();
- var myComponent = container.Resolve<MyComponent>(new TypedParameter(typeof(int), 123));
-
- null
- If the object is null then an null
- If the object is null then an null
- If the object is null then an null
- If the object is null then an null
- If the object is null then an null
- If the object is null then an null
- If the object is not null then an null
- If the object is not null then an null
- If the object is not null then an null
- If the object is not null then an null
- If the object is not null then an null
- If the object is not null then an NaN value.
- If the object is not NaN then an NaN value.
- If the object is not NaN then an NaN value.
- If the object is not NaN then an NaN value.
- If the object is not NaN then an NaN value.
- If the object is not NaN then an NaN value.
- If the object is not NaN then an null
- If the object is null then an null
- If the object is null then an null
- If the object is null then an null
- If the object is null then an null
- If the object is not null then an null
- If the object is not null then an null
- If the object is not null then an null
- If the object is not null then an NaN value.
- If the object is not NaN then an NaN value.
- If the object is not NaN then an NaN value.
- If the object is not NaN then an NaN value.
- If the object is not NaN then an null
- If the object is null then an null
- If the object is null then an null
- If the object is null then an null
- If the object is null then an null
- If the object is not null then an null
- If the object is not null then an null
- If the object is not null then an null
- If the object is not null then an NaN value.
- If the object is not NaN then an NaN value.
- If the object is not NaN then an NaN value.
- If the object is not NaN then an NaN value.
- If the object is not NaN then an null
- If the object is null then an null
- If the object is null then an null
- If the object is null then an null
- If the object is null then an null
- If the object is not null then an null
- If the object is not null then an null
- If the object is not null then an null
- If the object is not null then an NaN value.
- If the object is not NaN then an NaN value.
- If the object is not NaN then an NaN value.
- If the object is not NaN then an NaN value.
- If the object is not NaN then an null
- If the object is null then an null
- If the object is null then an null
- If the object is null then an null
- If the object is null then an null
- If the object is not null then an null
- If the object is not null then an null
- If the object is not null then an null
- If the object is not null then an NaN value.
- If the object is not NaN then an NaN value.
- If the object is not NaN then an NaN value.
- If the object is not NaN then an NaN value.
- If the object is not NaN then an null
- If the object is null then an null
- If the object is null then an null
- If the object is null then an null
- If the object is null then an null
- If the object is not null then an null
- If the object is not null then an null
- If the object is not null then an null
- If the object is not null then an NaN value.
- If the object is not NaN then an NaN value.
- If the object is not NaN then an NaN value.
- If the object is not NaN then an NaN value.
- If the object is not NaN then an null
- If the object is null then an null
- If the object is null then an null
- If the object is null then an null
- If the object is null then an null
- If the object is not null then an null
- If the object is not null then an null
- If the object is not null then an null
- If the object is not null then an NaN value.
- If the object is not NaN then an NaN value.
- If the object is not NaN then an NaN value.
- If the object is not NaN then an NaN value.
- If the object is not NaN then an
- CREATE TABLE [dbo].[Log] (
- [ID] [int] IDENTITY (1, 1) NOT NULL ,
- [Date] [datetime] NOT NULL ,
- [Thread] [varchar] (255) NOT NULL ,
- [Level] [varchar] (20) NOT NULL ,
- [Logger] [varchar] (255) NOT NULL ,
- [Message] [varchar] (4000) NOT NULL
- ) ON [PRIMARY]
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- "DSN=MS Access Database;UID=admin;PWD=;SystemDB=C:\data\System.mdw;SafeTransactions = 0;FIL=MS Access;DriverID = 25;DBQ=C:\data\train33.mdb"
- "Driver={Microsoft Access Driver (*.mdb)};DBQ=C:\Work\cvs_root\log4net-1.2\access.mdb;UID=;PWD=;"
- "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Work\cvs_root\log4net-1.2\access.mdb;User Id=;Password=;"
- System.Data.OleDb.OleDbConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
- System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
- Microsoft.Data.Odbc.OdbcConnection,Microsoft.Data.Odbc,version=1.0.3300.0,publicKeyToken=b77a5c561934e089,culture=neutral
- This is an optional package that you can download from
- http://msdn.microsoft.com/downloads
- search for ODBC .NET Data Provider.
- System.Data.OracleClient.OracleConnection, System.Data.OracleClient, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
- This is an optional package that you can download from
- http://msdn.microsoft.com/downloads
- search for .NET Managed Provider for Oracle.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- <mapping>
- <level value="ERROR" />
- <eventLogEntryType value="Error" />
- </mapping>
- <mapping>
- <level value="DEBUG" />
- <eventLogEntryType value="Information" />
- </mapping>
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- IPEndPoint remoteEndPoint = new IPEndPoint(IPAddress.Any, 0);
- UdpClient udpClient;
- byte[] buffer;
- string loggingEvent;
-
- try
- {
- udpClient = new UdpClient(8080);
-
- while(true)
- {
- buffer = udpClient.Receive(ref remoteEndPoint);
- loggingEvent = System.Text.Encoding.Unicode.GetString(buffer);
- Console.WriteLine(loggingEvent);
- }
- }
- catch(Exception e)
- {
- Console.WriteLine(e.ToString());
- }
-
-
- Dim remoteEndPoint as IPEndPoint
- Dim udpClient as UdpClient
- Dim buffer as Byte()
- Dim loggingEvent as String
-
- Try
- remoteEndPoint = new IPEndPoint(IPAddress.Any, 0)
- udpClient = new UdpClient(8080)
-
- While True
- buffer = udpClient.Receive(ByRef remoteEndPoint)
- loggingEvent = System.Text.Encoding.Unicode.GetString(buffer)
- Console.WriteLine(loggingEvent)
- Wend
- Catch e As Exception
- Console.WriteLine(e.ToString())
- End Try
-
-
-
-
-
-
-
-
-
- using log4net.Config;
- using System.IO;
- using System.Configuration;
-
- ...
-
- DOMConfigurator.Configure(new FileInfo(ConfigurationSettings.AppSettings["log4net-config-file"]));
-
-
-
-
-
-
-
-
-
- using log4net.Config;
- using System.IO;
- using System.Configuration;
-
- ...
-
- DOMConfigurator.Configure(new FileInfo(ConfigurationSettings.AppSettings["log4net-config-file"]));
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- log4net configuration XML goes here
-
-
-
-
-
-
-
-
-
- using log4net.Config;
- using System.IO;
- using System.Configuration;
-
- ...
-
- XmlConfigurator.Configure(new FileInfo(ConfigurationSettings.AppSettings["log4net-config-file"]));
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- using log4net.Config;
- using System.IO;
- using System.Configuration;
-
- ...
-
- XmlConfigurator.Configure(new FileInfo(ConfigurationSettings.AppSettings["log4net-config-file"]));
-
-
-
-
-
-
-
-
-
- ILog log = LogManager.GetLogger("application-log");
-
- log.Info("Application Start");
- log.Debug("This is a debug message");
-
- if (log.IsDebugEnabled)
- {
- log.Debug("This is another debug message");
- }
-
-
- log.Debug("This is entry number: " + i );
-
-
- if (log.IsDebugEnabled)
- {
- log.Debug("This is entry number: " + i );
- }
-
-
- private static readonly bool isDebugEnabled = log.IsDebugEnabled;
-
-
- if (isDebugEnabled)
- {
- log.Debug("This is entry number: " + i );
- }
-
-
- log.Debug("This is entry number: " + i );
-
-
- if (log.IsDebugEnabled())
- {
- log.Debug("This is entry number: " + i );
- }
-
-
- {key1=value1, key2=value2, key3=value3}
-
-
- {key1=value1, key2=value2, key3=value3}
-
-
- ILog log = LogManager.GetLogger(typeof(TestApp));
- log.Debug("Message 1");
- log.Warn("Message 2");
-
-
- DEBUG [main]: Message 1
- WARN [main]: Message 2
-
- | Format modifier | -left justify | -minimum width | -maximum width | -comment | -
|---|---|---|---|---|
| %20logger | -false | -20 | -none | -
- |
-
| %-20logger | -true | -20 | -none | -
- |
-
| %.30logger | -NA | -none | -30 | -
- |
-
| false | -20 | -30 | -
- |
- |
| %-20.30logger | -true | -20 | -30 | -
- |
-
%timestamp [%thread] %level %logger %ndc - %message%newline
- %-6timestamp [%15.15thread] %-5level %30.30logger %ndc - %message%newline
-
- StringWriter writer = new StringWriter();
- Layout.Format(writer, loggingEvent);
- string formattedEvent = writer.ToString();
-
-
- DEBUG - Hello world
-
-
- <?xml version="1.0" ?>
-
- <!DOCTYPE log4net:events SYSTEM "log4net-events.dtd" [<!ENTITY data SYSTEM "abc">]>
-
- <log4net:events version="1.2" xmlns:log4net="http://logging.apache.org/log4net/schemas/log4net-events-1.2>
- &data;
- </log4net:events>
-
-
- using(log4net.LogicalThreadContext.Stacks["NDC"].Push("Stack_Message"))
- {
- log.Warn("This should have an ThreadContext Stack message");
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- string s = OptionConverter.SubstituteVariables("Value of key is ${key}.");
-
-
- string s = OptionConverter.SubstituteVariables("Value of nonExistentKey is [${nonExistentKey}]");
-
-
- using(log4net.ThreadContext.Stacks["NDC"].Push("Stack_Message"))
- {
- log.Warn("This should have an ThreadContext Stack message");
- }
-
-
- GlobalContext.Properties["hostname"] = Environment.MachineName;
-
-
- LogicalThreadContext.Properties["user"] = userName;
- log.Info("This log message has a LogicalThreadContext Property called 'user'");
-
-
- using(LogicalThreadContext.Stacks["LDC"].Push("my context message"))
- {
- log.Info("This log message has a LogicalThreadContext Stack message that includes 'my context message'");
-
- } // at the end of the using block the message is automatically popped
-
-
- ILog log = LogManager.GetLogger("application-log");
-
- log.Info("Application Start");
- log.Debug("This is a debug message");
-
- if (log.IsDebugEnabled)
- {
- log.Debug("This is another debug message");
- }
-
-
- using(NDC.Push("my context message"))
- {
- ... all log calls will have 'my context message' included ...
-
- } // at the end of the using block the message is automatically removed
-
-
- using(log4net.NDC.Push("NDC_Message"))
- {
- log.Warn("This should have an NDC message");
- }
-
-
- var someValue = "ExampleContext"
- using(log4net.NDC.PushFormat("NDC_Message {0}", someValue))
- {
- log.Warn("This should have an NDC message");
- }
-
-
- ThreadContext.Properties["user"] = userName;
- log.Info("This log message has a ThreadContext Property called 'user'");
-
-
- using(ThreadContext.Stacks["NDC"].Push("my context message"))
- {
- log.Info("This log message has a ThreadContext Stack message that includes 'my context message'");
-
- } // at the end of the using block the message is automatically popped
-
-
- CREATE TABLE [dbo].[Log] (
- [ID] [int] IDENTITY (1, 1) NOT NULL ,
- [Date] [datetime] NOT NULL ,
- [Thread] [varchar] (255) NOT NULL ,
- [Level] [varchar] (20) NOT NULL ,
- [Logger] [varchar] (255) NOT NULL ,
- [Message] [varchar] (4000) NOT NULL
- ) ON [PRIMARY]
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- "DSN=MS Access Database;UID=admin;PWD=;SystemDB=C:\data\System.mdw;SafeTransactions = 0;FIL=MS Access;DriverID = 25;DBQ=C:\data\train33.mdb"
- "Driver={Microsoft Access Driver (*.mdb)};DBQ=C:\Work\cvs_root\log4net-1.2\access.mdb;UID=;PWD=;"
- "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Work\cvs_root\log4net-1.2\access.mdb;User Id=;Password=;"
- System.Data.OleDb.OleDbConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
- System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
- Microsoft.Data.Odbc.OdbcConnection,Microsoft.Data.Odbc,version=1.0.3300.0,publicKeyToken=b77a5c561934e089,culture=neutral
- This is an optional package that you can download from
- http://msdn.microsoft.com/downloads
- search for ODBC .NET Data Provider.
- System.Data.OracleClient.OracleConnection, System.Data.OracleClient, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
- This is an optional package that you can download from
- http://msdn.microsoft.com/downloads
- search for .NET Managed Provider for Oracle.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- <mapping>
- <level value="ERROR" />
- <eventLogEntryType value="Error" />
- </mapping>
- <mapping>
- <level value="DEBUG" />
- <eventLogEntryType value="Information" />
- </mapping>
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- IPEndPoint remoteEndPoint = new IPEndPoint(IPAddress.Any, 0);
- UdpClient udpClient;
- byte[] buffer;
- string loggingEvent;
-
- try
- {
- udpClient = new UdpClient(8080);
-
- while(true)
- {
- buffer = udpClient.Receive(ref remoteEndPoint);
- loggingEvent = System.Text.Encoding.Unicode.GetString(buffer);
- Console.WriteLine(loggingEvent);
- }
- }
- catch(Exception e)
- {
- Console.WriteLine(e.ToString());
- }
-
-
- Dim remoteEndPoint as IPEndPoint
- Dim udpClient as UdpClient
- Dim buffer as Byte()
- Dim loggingEvent as String
-
- Try
- remoteEndPoint = new IPEndPoint(IPAddress.Any, 0)
- udpClient = new UdpClient(8080)
-
- While True
- buffer = udpClient.Receive(ByRef remoteEndPoint)
- loggingEvent = System.Text.Encoding.Unicode.GetString(buffer)
- Console.WriteLine(loggingEvent)
- Wend
- Catch e As Exception
- Console.WriteLine(e.ToString())
- End Try
-
-
-
-
-
-
-
-
-
- using log4net.Config;
- using System.IO;
- using System.Configuration;
-
- ...
-
- DOMConfigurator.Configure(new FileInfo(ConfigurationSettings.AppSettings["log4net-config-file"]));
-
-
-
-
-
-
-
-
-
- using log4net.Config;
- using System.IO;
- using System.Configuration;
-
- ...
-
- DOMConfigurator.Configure(new FileInfo(ConfigurationSettings.AppSettings["log4net-config-file"]));
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- log4net configuration XML goes here
-
-
-
-
-
-
-
-
-
- using log4net.Config;
- using System.IO;
- using System.Configuration;
-
- ...
-
- XmlConfigurator.Configure(new FileInfo(ConfigurationSettings.AppSettings["log4net-config-file"]));
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- using log4net.Config;
- using System.IO;
- using System.Configuration;
-
- ...
-
- XmlConfigurator.Configure(new FileInfo(ConfigurationSettings.AppSettings["log4net-config-file"]));
-
-
-
-
-
-
-
-
-
- ILog log = LogManager.GetLogger("application-log");
-
- log.Info("Application Start");
- log.Debug("This is a debug message");
-
- if (log.IsDebugEnabled)
- {
- log.Debug("This is another debug message");
- }
-
-
- log.Debug("This is entry number: " + i );
-
-
- if (log.IsDebugEnabled)
- {
- log.Debug("This is entry number: " + i );
- }
-
-
- private static readonly bool isDebugEnabled = log.IsDebugEnabled;
-
-
- if (isDebugEnabled)
- {
- log.Debug("This is entry number: " + i );
- }
-
-
- log.Debug("This is entry number: " + i );
-
-
- if (log.IsDebugEnabled())
- {
- log.Debug("This is entry number: " + i );
- }
-
-
- {key1=value1, key2=value2, key3=value3}
-
-
- {key1=value1, key2=value2, key3=value3}
-
-
- ILog log = LogManager.GetLogger(typeof(TestApp));
- log.Debug("Message 1");
- log.Warn("Message 2");
-
-
- DEBUG [main]: Message 1
- WARN [main]: Message 2
-
- | Format modifier | -left justify | -minimum width | -maximum width | -comment | -
|---|---|---|---|---|
| %20logger | -false | -20 | -none | -
- |
-
| %-20logger | -true | -20 | -none | -
- |
-
| %.30logger | -NA | -none | -30 | -
- |
-
| false | -20 | -30 | -
- |
- |
| %-20.30logger | -true | -20 | -30 | -
- |
-
%timestamp [%thread] %level %logger %ndc - %message%newline
- %-6timestamp [%15.15thread] %-5level %30.30logger %ndc - %message%newline
-
- StringWriter writer = new StringWriter();
- Layout.Format(writer, loggingEvent);
- string formattedEvent = writer.ToString();
-
-
- DEBUG - Hello world
-
-
- <?xml version="1.0" ?>
-
- <!DOCTYPE log4net:events SYSTEM "log4net-events.dtd" [<!ENTITY data SYSTEM "abc">]>
-
- <log4net:events version="1.2" xmlns:log4net="http://logging.apache.org/log4net/schemas/log4net-events-1.2>
- &data;
- </log4net:events>
-
-
- using log4net.Util;
-
- ILog log = LogManager.GetLogger("application-log");
-
- log.InfoExt("Application Start");
- log.DebugExt("This is a debug message");
-
-
- using(log4net.LogicalThreadContext.Stacks["NDC"].Push("Stack_Message"))
- {
- log.Warn("This should have an ThreadContext Stack message");
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- string s = OptionConverter.SubstituteVariables("Value of key is ${key}.");
-
-
- string s = OptionConverter.SubstituteVariables("Value of nonExistentKey is [${nonExistentKey}]");
-
-
- using(log4net.ThreadContext.Stacks["NDC"].Push("Stack_Message"))
- {
- log.Warn("This should have an ThreadContext Stack message");
- }
-
-
- GlobalContext.Properties["hostname"] = Environment.MachineName;
-
-
- LogicalThreadContext.Properties["user"] = userName;
- log.Info("This log message has a LogicalThreadContext Property called 'user'");
-
-
- using(LogicalThreadContext.Stacks["LDC"].Push("my context message"))
- {
- log.Info("This log message has a LogicalThreadContext Stack message that includes 'my context message'");
-
- } // at the end of the using block the message is automatically popped
-
-
- ILog log = LogManager.GetLogger("application-log");
-
- log.Info("Application Start");
- log.Debug("This is a debug message");
-
- if (log.IsDebugEnabled)
- {
- log.Debug("This is another debug message");
- }
-
-
- using(NDC.Push("my context message"))
- {
- ... all log calls will have 'my context message' included ...
-
- } // at the end of the using block the message is automatically removed
-
-
- using(log4net.NDC.Push("NDC_Message"))
- {
- log.Warn("This should have an NDC message");
- }
-
-
- var someValue = "ExampleContext"
- using(log4net.NDC.PushFormat("NDC_Message {0}", someValue))
- {
- log.Warn("This should have an NDC message");
- }
-
-
- ThreadContext.Properties["user"] = userName;
- log.Info("This log message has a ThreadContext Property called 'user'");
-
-
- using(ThreadContext.Stacks["NDC"].Push("my context message"))
- {
- log.Info("This log message has a ThreadContext Stack message that includes 'my context message'");
-
- } // at the end of the using block the message is automatically popped
-
-
- CREATE TABLE [dbo].[Log] (
- [ID] [int] IDENTITY (1, 1) NOT NULL ,
- [Date] [datetime] NOT NULL ,
- [Thread] [varchar] (255) NOT NULL ,
- [Level] [varchar] (20) NOT NULL ,
- [Logger] [varchar] (255) NOT NULL ,
- [Message] [varchar] (4000) NOT NULL
- ) ON [PRIMARY]
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- "DSN=MS Access Database;UID=admin;PWD=;SystemDB=C:\data\System.mdw;SafeTransactions = 0;FIL=MS Access;DriverID = 25;DBQ=C:\data\train33.mdb"
- "Driver={Microsoft Access Driver (*.mdb)};DBQ=C:\Work\cvs_root\log4net-1.2\access.mdb;UID=;PWD=;"
- "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Work\cvs_root\log4net-1.2\access.mdb;User Id=;Password=;"
- System.Data.OleDb.OleDbConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
- System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
- Microsoft.Data.Odbc.OdbcConnection,Microsoft.Data.Odbc,version=1.0.3300.0,publicKeyToken=b77a5c561934e089,culture=neutral
- This is an optional package that you can download from
- http://msdn.microsoft.com/downloads
- search for ODBC .NET Data Provider.
- System.Data.OracleClient.OracleConnection, System.Data.OracleClient, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
- This is an optional package that you can download from
- http://msdn.microsoft.com/downloads
- search for .NET Managed Provider for Oracle.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- <mapping>
- <level value="ERROR" />
- <eventLogEntryType value="Error" />
- </mapping>
- <mapping>
- <level value="DEBUG" />
- <eventLogEntryType value="Information" />
- </mapping>
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- IPEndPoint remoteEndPoint = new IPEndPoint(IPAddress.Any, 0);
- UdpClient udpClient;
- byte[] buffer;
- string loggingEvent;
-
- try
- {
- udpClient = new UdpClient(8080);
-
- while(true)
- {
- buffer = udpClient.Receive(ref remoteEndPoint);
- loggingEvent = System.Text.Encoding.Unicode.GetString(buffer);
- Console.WriteLine(loggingEvent);
- }
- }
- catch(Exception e)
- {
- Console.WriteLine(e.ToString());
- }
-
-
- Dim remoteEndPoint as IPEndPoint
- Dim udpClient as UdpClient
- Dim buffer as Byte()
- Dim loggingEvent as String
-
- Try
- remoteEndPoint = new IPEndPoint(IPAddress.Any, 0)
- udpClient = new UdpClient(8080)
-
- While True
- buffer = udpClient.Receive(ByRef remoteEndPoint)
- loggingEvent = System.Text.Encoding.Unicode.GetString(buffer)
- Console.WriteLine(loggingEvent)
- Wend
- Catch e As Exception
- Console.WriteLine(e.ToString())
- End Try
-
-
-
-
-
-
-
-
-
- using log4net.Config;
- using System.IO;
- using System.Configuration;
-
- ...
-
- DOMConfigurator.Configure(new FileInfo(ConfigurationSettings.AppSettings["log4net-config-file"]));
-
-
-
-
-
-
-
-
-
- using log4net.Config;
- using System.IO;
- using System.Configuration;
-
- ...
-
- DOMConfigurator.Configure(new FileInfo(ConfigurationSettings.AppSettings["log4net-config-file"]));
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- log4net configuration XML goes here
-
-
-
-
-
-
-
-
-
- using log4net.Config;
- using System.IO;
- using System.Configuration;
-
- ...
-
- XmlConfigurator.Configure(new FileInfo(ConfigurationSettings.AppSettings["log4net-config-file"]));
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- using log4net.Config;
- using System.IO;
- using System.Configuration;
-
- ...
-
- XmlConfigurator.Configure(new FileInfo(ConfigurationSettings.AppSettings["log4net-config-file"]));
-
-
-
-
-
-
-
-
-
- ILog log = LogManager.GetLogger("application-log");
-
- log.Info("Application Start");
- log.Debug("This is a debug message");
-
- if (log.IsDebugEnabled)
- {
- log.Debug("This is another debug message");
- }
-
-
- log.Debug("This is entry number: " + i );
-
-
- if (log.IsDebugEnabled)
- {
- log.Debug("This is entry number: " + i );
- }
-
-
- private static readonly bool isDebugEnabled = log.IsDebugEnabled;
-
-
- if (isDebugEnabled)
- {
- log.Debug("This is entry number: " + i );
- }
-
-
- log.Debug("This is entry number: " + i );
-
-
- if (log.IsDebugEnabled())
- {
- log.Debug("This is entry number: " + i );
- }
-
-
- {key1=value1, key2=value2, key3=value3}
-
-
- {key1=value1, key2=value2, key3=value3}
-
-
- ILog log = LogManager.GetLogger(typeof(TestApp));
- log.Debug("Message 1");
- log.Warn("Message 2");
-
-
- DEBUG [main]: Message 1
- WARN [main]: Message 2
-
- | Format modifier | -left justify | -minimum width | -maximum width | -comment | -
|---|---|---|---|---|
| %20logger | -false | -20 | -none | -
- |
-
| %-20logger | -true | -20 | -none | -
- |
-
| %.30logger | -NA | -none | -30 | -
- |
-
| false | -20 | -30 | -
- |
- |
| %-20.30logger | -true | -20 | -30 | -
- |
-
%timestamp [%thread] %level %logger %ndc - %message%newline
- %-6timestamp [%15.15thread] %-5level %30.30logger %ndc - %message%newline
-
- StringWriter writer = new StringWriter();
- Layout.Format(writer, loggingEvent);
- string formattedEvent = writer.ToString();
-
-
- DEBUG - Hello world
-
-
- <?xml version="1.0" ?>
-
- <!DOCTYPE log4net:events SYSTEM "log4net-events.dtd" [<!ENTITY data SYSTEM "abc">]>
-
- <log4net:events version="1.2" xmlns:log4net="http://logging.apache.org/log4net/schemas/log4net-events-1.2>
- &data;
- </log4net:events>
-
-
- using log4net.Util;
-
- ILog log = LogManager.GetLogger("application-log");
-
- log.InfoExt("Application Start");
- log.DebugExt("This is a debug message");
-
-
- using(log4net.LogicalThreadContext.Stacks["NDC"].Push("Stack_Message"))
- {
- log.Warn("This should have an ThreadContext Stack message");
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- string s = OptionConverter.SubstituteVariables("Value of key is ${key}.");
-
-
- string s = OptionConverter.SubstituteVariables("Value of nonExistentKey is [${nonExistentKey}]");
-
-
- using(log4net.ThreadContext.Stacks["NDC"].Push("Stack_Message"))
- {
- log.Warn("This should have an ThreadContext Stack message");
- }
-
-
- GlobalContext.Properties["hostname"] = Environment.MachineName;
-
-
- LogicalThreadContext.Properties["user"] = userName;
- log.Info("This log message has a LogicalThreadContext Property called 'user'");
-
-
- using(LogicalThreadContext.Stacks["LDC"].Push("my context message"))
- {
- log.Info("This log message has a LogicalThreadContext Stack message that includes 'my context message'");
-
- } // at the end of the using block the message is automatically popped
-
-
- ILog log = LogManager.GetLogger("application-log");
-
- log.Info("Application Start");
- log.Debug("This is a debug message");
-
- if (log.IsDebugEnabled)
- {
- log.Debug("This is another debug message");
- }
-
-
- using(NDC.Push("my context message"))
- {
- ... all log calls will have 'my context message' included ...
-
- } // at the end of the using block the message is automatically removed
-
-
- using(log4net.NDC.Push("NDC_Message"))
- {
- log.Warn("This should have an NDC message");
- }
-
-
- var someValue = "ExampleContext"
- using(log4net.NDC.PushFormat("NDC_Message {0}", someValue))
- {
- log.Warn("This should have an NDC message");
- }
-
-
- ThreadContext.Properties["user"] = userName;
- log.Info("This log message has a ThreadContext Property called 'user'");
-
-
- using(ThreadContext.Stacks["NDC"].Push("my context message"))
- {
- log.Info("This log message has a ThreadContext Stack message that includes 'my context message'");
-
- } // at the end of the using block the message is automatically popped
-
-
- CREATE TABLE [dbo].[Log] (
- [ID] [int] IDENTITY (1, 1) NOT NULL ,
- [Date] [datetime] NOT NULL ,
- [Thread] [varchar] (255) NOT NULL ,
- [Level] [varchar] (20) NOT NULL ,
- [Logger] [varchar] (255) NOT NULL ,
- [Message] [varchar] (4000) NOT NULL
- ) ON [PRIMARY]
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- "DSN=MS Access Database;UID=admin;PWD=;SystemDB=C:\data\System.mdw;SafeTransactions = 0;FIL=MS Access;DriverID = 25;DBQ=C:\data\train33.mdb"
- "Driver={Microsoft Access Driver (*.mdb)};DBQ=C:\Work\cvs_root\log4net-1.2\access.mdb;UID=;PWD=;"
- "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Work\cvs_root\log4net-1.2\access.mdb;User Id=;Password=;"
- System.Data.OleDb.OleDbConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
- System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
- Microsoft.Data.Odbc.OdbcConnection,Microsoft.Data.Odbc,version=1.0.3300.0,publicKeyToken=b77a5c561934e089,culture=neutral
- This is an optional package that you can download from
- http://msdn.microsoft.com/downloads
- search for ODBC .NET Data Provider.
- System.Data.OracleClient.OracleConnection, System.Data.OracleClient, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
- This is an optional package that you can download from
- http://msdn.microsoft.com/downloads
- search for .NET Managed Provider for Oracle.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- <mapping>
- <level value="ERROR" />
- <eventLogEntryType value="Error" />
- </mapping>
- <mapping>
- <level value="DEBUG" />
- <eventLogEntryType value="Information" />
- </mapping>
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- IPEndPoint remoteEndPoint = new IPEndPoint(IPAddress.Any, 0);
- UdpClient udpClient;
- byte[] buffer;
- string loggingEvent;
-
- try
- {
- udpClient = new UdpClient(8080);
-
- while(true)
- {
- buffer = udpClient.Receive(ref remoteEndPoint);
- loggingEvent = System.Text.Encoding.Unicode.GetString(buffer);
- Console.WriteLine(loggingEvent);
- }
- }
- catch(Exception e)
- {
- Console.WriteLine(e.ToString());
- }
-
-
- Dim remoteEndPoint as IPEndPoint
- Dim udpClient as UdpClient
- Dim buffer as Byte()
- Dim loggingEvent as String
-
- Try
- remoteEndPoint = new IPEndPoint(IPAddress.Any, 0)
- udpClient = new UdpClient(8080)
-
- While True
- buffer = udpClient.Receive(ByRef remoteEndPoint)
- loggingEvent = System.Text.Encoding.Unicode.GetString(buffer)
- Console.WriteLine(loggingEvent)
- Wend
- Catch e As Exception
- Console.WriteLine(e.ToString())
- End Try
-
-
-
-
-
-
-
-
-
- using log4net.Config;
- using System.IO;
- using System.Configuration;
-
- ...
-
- DOMConfigurator.Configure(new FileInfo(ConfigurationSettings.AppSettings["log4net-config-file"]));
-
-
-
-
-
-
-
-
-
- using log4net.Config;
- using System.IO;
- using System.Configuration;
-
- ...
-
- DOMConfigurator.Configure(new FileInfo(ConfigurationSettings.AppSettings["log4net-config-file"]));
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- log4net configuration XML goes here
-
-
-
-
-
-
-
-
-
- using log4net.Config;
- using System.IO;
- using System.Configuration;
-
- ...
-
- XmlConfigurator.Configure(new FileInfo(ConfigurationSettings.AppSettings["log4net-config-file"]));
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- using log4net.Config;
- using System.IO;
- using System.Configuration;
-
- ...
-
- XmlConfigurator.Configure(new FileInfo(ConfigurationSettings.AppSettings["log4net-config-file"]));
-
-
-
-
-
-
-
-
-
- ILog log = LogManager.GetLogger("application-log");
-
- log.Info("Application Start");
- log.Debug("This is a debug message");
-
- if (log.IsDebugEnabled)
- {
- log.Debug("This is another debug message");
- }
-
-
- log.Debug("This is entry number: " + i );
-
-
- if (log.IsDebugEnabled)
- {
- log.Debug("This is entry number: " + i );
- }
-
-
- private static readonly bool isDebugEnabled = log.IsDebugEnabled;
-
-
- if (isDebugEnabled)
- {
- log.Debug("This is entry number: " + i );
- }
-
-
- log.Debug("This is entry number: " + i );
-
-
- if (log.IsDebugEnabled())
- {
- log.Debug("This is entry number: " + i );
- }
-
-
- {key1=value1, key2=value2, key3=value3}
-
-
- {key1=value1, key2=value2, key3=value3}
-
-
- ILog log = LogManager.GetLogger(typeof(TestApp));
- log.Debug("Message 1");
- log.Warn("Message 2");
-
-
- DEBUG [main]: Message 1
- WARN [main]: Message 2
-
- | Format modifier | -left justify | -minimum width | -maximum width | -comment | -
|---|---|---|---|---|
| %20logger | -false | -20 | -none | -
- |
-
| %-20logger | -true | -20 | -none | -
- |
-
| %.30logger | -NA | -none | -30 | -
- |
-
| false | -20 | -30 | -
- |
- |
| %-20.30logger | -true | -20 | -30 | -
- |
-
%timestamp [%thread] %level %logger %ndc - %message%newline
- %-6timestamp [%15.15thread] %-5level %30.30logger %ndc - %message%newline
-
- StringWriter writer = new StringWriter();
- Layout.Format(writer, loggingEvent);
- string formattedEvent = writer.ToString();
-
-
- DEBUG - Hello world
-
-
- <?xml version="1.0" ?>
-
- <!DOCTYPE log4net:events SYSTEM "log4net-events.dtd" [<!ENTITY data SYSTEM "abc">]>
-
- <log4net:events version="1.2" xmlns:log4net="http://logging.apache.org/log4net/schemas/log4net-events-1.2>
- &data;
- </log4net:events>
-
-
- using log4net.Util;
-
- ILog log = LogManager.GetLogger("application-log");
-
- log.InfoExt("Application Start");
- log.DebugExt("This is a debug message");
-
-
- using(log4net.LogicalThreadContext.Stacks["NDC"].Push("Stack_Message"))
- {
- log.Warn("This should have an ThreadContext Stack message");
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- string s = OptionConverter.SubstituteVariables("Value of key is ${key}.");
-
-
- string s = OptionConverter.SubstituteVariables("Value of nonExistentKey is [${nonExistentKey}]");
-
-
- using(log4net.ThreadContext.Stacks["NDC"].Push("Stack_Message"))
- {
- log.Warn("This should have an ThreadContext Stack message");
- }
-
-
- GlobalContext.Properties["hostname"] = Environment.MachineName;
-
-
- LogicalThreadContext.Properties["user"] = userName;
- log.Info("This log message has a LogicalThreadContext Property called 'user'");
-
-
- using(LogicalThreadContext.Stacks["LDC"].Push("my context message"))
- {
- log.Info("This log message has a LogicalThreadContext Stack message that includes 'my context message'");
-
- } // at the end of the using block the message is automatically popped
-
-
- ILog log = LogManager.GetLogger("application-log");
-
- log.Info("Application Start");
- log.Debug("This is a debug message");
-
- if (log.IsDebugEnabled)
- {
- log.Debug("This is another debug message");
- }
-
-
- using(NDC.Push("my context message"))
- {
- ... all log calls will have 'my context message' included ...
-
- } // at the end of the using block the message is automatically removed
-
-
- using(log4net.NDC.Push("NDC_Message"))
- {
- log.Warn("This should have an NDC message");
- }
-
-
- var someValue = "ExampleContext"
- using(log4net.NDC.PushFormat("NDC_Message {0}", someValue))
- {
- log.Warn("This should have an NDC message");
- }
-
-
- ThreadContext.Properties["user"] = userName;
- log.Info("This log message has a ThreadContext Property called 'user'");
-
-
- using(ThreadContext.Stacks["NDC"].Push("my context message"))
- {
- log.Info("This log message has a ThreadContext Stack message that includes 'my context message'");
-
- } // at the end of the using block the message is automatically popped
-
-
- CREATE TABLE [dbo].[Log] (
- [ID] [int] IDENTITY (1, 1) NOT NULL ,
- [Date] [datetime] NOT NULL ,
- [Thread] [varchar] (255) NOT NULL ,
- [Level] [varchar] (20) NOT NULL ,
- [Logger] [varchar] (255) NOT NULL ,
- [Message] [varchar] (4000) NOT NULL
- ) ON [PRIMARY]
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- "DSN=MS Access Database;UID=admin;PWD=;SystemDB=C:\data\System.mdw;SafeTransactions = 0;FIL=MS Access;DriverID = 25;DBQ=C:\data\train33.mdb"
- "Driver={Microsoft Access Driver (*.mdb)};DBQ=C:\Work\cvs_root\log4net-1.2\access.mdb;UID=;PWD=;"
- "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Work\cvs_root\log4net-1.2\access.mdb;User Id=;Password=;"
- System.Data.OleDb.OleDbConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
- System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
- Microsoft.Data.Odbc.OdbcConnection,Microsoft.Data.Odbc,version=1.0.3300.0,publicKeyToken=b77a5c561934e089,culture=neutral
- This is an optional package that you can download from
- http://msdn.microsoft.com/downloads
- search for ODBC .NET Data Provider.
- System.Data.OracleClient.OracleConnection, System.Data.OracleClient, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
- This is an optional package that you can download from
- http://msdn.microsoft.com/downloads
- search for .NET Managed Provider for Oracle.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- <mapping>
- <level value="ERROR" />
- <eventLogEntryType value="Error" />
- </mapping>
- <mapping>
- <level value="DEBUG" />
- <eventLogEntryType value="Information" />
- </mapping>
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- IPEndPoint remoteEndPoint = new IPEndPoint(IPAddress.Any, 0);
- UdpClient udpClient;
- byte[] buffer;
- string loggingEvent;
-
- try
- {
- udpClient = new UdpClient(8080);
-
- while(true)
- {
- buffer = udpClient.Receive(ref remoteEndPoint);
- loggingEvent = System.Text.Encoding.Unicode.GetString(buffer);
- Console.WriteLine(loggingEvent);
- }
- }
- catch(Exception e)
- {
- Console.WriteLine(e.ToString());
- }
-
-
- Dim remoteEndPoint as IPEndPoint
- Dim udpClient as UdpClient
- Dim buffer as Byte()
- Dim loggingEvent as String
-
- Try
- remoteEndPoint = new IPEndPoint(IPAddress.Any, 0)
- udpClient = new UdpClient(8080)
-
- While True
- buffer = udpClient.Receive(ByRef remoteEndPoint)
- loggingEvent = System.Text.Encoding.Unicode.GetString(buffer)
- Console.WriteLine(loggingEvent)
- Wend
- Catch e As Exception
- Console.WriteLine(e.ToString())
- End Try
-
-
-
-
-
-
-
-
-
- using log4net.Config;
- using System.IO;
- using System.Configuration;
-
- ...
-
- DOMConfigurator.Configure(new FileInfo(ConfigurationSettings.AppSettings["log4net-config-file"]));
-
-
-
-
-
-
-
-
-
- using log4net.Config;
- using System.IO;
- using System.Configuration;
-
- ...
-
- DOMConfigurator.Configure(new FileInfo(ConfigurationSettings.AppSettings["log4net-config-file"]));
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- log4net configuration XML goes here
-
-
-
-
-
-
-
-
-
- using log4net.Config;
- using System.IO;
- using System.Configuration;
-
- ...
-
- XmlConfigurator.Configure(new FileInfo(ConfigurationSettings.AppSettings["log4net-config-file"]));
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- using log4net.Config;
- using System.IO;
- using System.Configuration;
-
- ...
-
- XmlConfigurator.Configure(new FileInfo(ConfigurationSettings.AppSettings["log4net-config-file"]));
-
-
-
-
-
-
-
-
-
- ILog log = LogManager.GetLogger("application-log");
-
- log.Info("Application Start");
- log.Debug("This is a debug message");
-
- if (log.IsDebugEnabled)
- {
- log.Debug("This is another debug message");
- }
-
-
- log.Debug("This is entry number: " + i );
-
-
- if (log.IsDebugEnabled)
- {
- log.Debug("This is entry number: " + i );
- }
-
-
- private static readonly bool isDebugEnabled = log.IsDebugEnabled;
-
-
- if (isDebugEnabled)
- {
- log.Debug("This is entry number: " + i );
- }
-
-
- log.Debug("This is entry number: " + i );
-
-
- if (log.IsDebugEnabled())
- {
- log.Debug("This is entry number: " + i );
- }
-
-
- {key1=value1, key2=value2, key3=value3}
-
-
- {key1=value1, key2=value2, key3=value3}
-
-
- ILog log = LogManager.GetLogger(typeof(TestApp));
- log.Debug("Message 1");
- log.Warn("Message 2");
-
-
- DEBUG [main]: Message 1
- WARN [main]: Message 2
-
- | Format modifier | -left justify | -minimum width | -maximum width | -comment | -
|---|---|---|---|---|
| %20logger | -false | -20 | -none | -
- |
-
| %-20logger | -true | -20 | -none | -
- |
-
| %.30logger | -NA | -none | -30 | -
- |
-
| false | -20 | -30 | -
- |
- |
| %-20.30logger | -true | -20 | -30 | -
- |
-
%timestamp [%thread] %level %logger %ndc - %message%newline
- %-6timestamp [%15.15thread] %-5level %30.30logger %ndc - %message%newline
-
- StringWriter writer = new StringWriter();
- Layout.Format(writer, loggingEvent);
- string formattedEvent = writer.ToString();
-
-
- DEBUG - Hello world
-
-
- <?xml version="1.0" ?>
-
- <!DOCTYPE log4net:events SYSTEM "log4net-events.dtd" [<!ENTITY data SYSTEM "abc">]>
-
- <log4net:events version="1.2" xmlns:log4net="http://logging.apache.org/log4net/schemas/log4net-events-1.2>
- &data;
- </log4net:events>
-
-
- using log4net.Util;
-
- ILog log = LogManager.GetLogger("application-log");
-
- log.InfoExt("Application Start");
- log.DebugExt("This is a debug message");
-
-
- using(log4net.LogicalThreadContext.Stacks["NDC"].Push("Stack_Message"))
- {
- log.Warn("This should have an ThreadContext Stack message");
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- string s = OptionConverter.SubstituteVariables("Value of key is ${key}.");
-
-
- string s = OptionConverter.SubstituteVariables("Value of nonExistentKey is [${nonExistentKey}]");
-
-
- using(log4net.ThreadContext.Stacks["NDC"].Push("Stack_Message"))
- {
- log.Warn("This should have an ThreadContext Stack message");
- }
-
-
- GlobalContext.Properties["hostname"] = Environment.MachineName;
-
-
- LogicalThreadContext.Properties["user"] = userName;
- log.Info("This log message has a LogicalThreadContext Property called 'user'");
-
-
- using(LogicalThreadContext.Stacks["LDC"].Push("my context message"))
- {
- log.Info("This log message has a LogicalThreadContext Stack message that includes 'my context message'");
-
- } // at the end of the using block the message is automatically popped
-
-
- ILog log = LogManager.GetLogger("application-log");
-
- log.Info("Application Start");
- log.Debug("This is a debug message");
-
- if (log.IsDebugEnabled)
- {
- log.Debug("This is another debug message");
- }
-
-
- using(NDC.Push("my context message"))
- {
- ... all log calls will have 'my context message' included ...
-
- } // at the end of the using block the message is automatically removed
-
-
- using(log4net.NDC.Push("NDC_Message"))
- {
- log.Warn("This should have an NDC message");
- }
-
-
- var someValue = "ExampleContext"
- using(log4net.NDC.PushFormat("NDC_Message {0}", someValue))
- {
- log.Warn("This should have an NDC message");
- }
-
-
- ThreadContext.Properties["user"] = userName;
- log.Info("This log message has a ThreadContext Property called 'user'");
-
-
- using(ThreadContext.Stacks["NDC"].Push("my context message"))
- {
- log.Info("This log message has a ThreadContext Stack message that includes 'my context message'");
-
- } // at the end of the using block the message is automatically popped
-
-
- CREATE TABLE [dbo].[Log] (
- [ID] [int] IDENTITY (1, 1) NOT NULL ,
- [Date] [datetime] NOT NULL ,
- [Thread] [varchar] (255) NOT NULL ,
- [Level] [varchar] (20) NOT NULL ,
- [Logger] [varchar] (255) NOT NULL ,
- [Message] [varchar] (4000) NOT NULL
- ) ON [PRIMARY]
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- "DSN=MS Access Database;UID=admin;PWD=;SystemDB=C:\data\System.mdw;SafeTransactions = 0;FIL=MS Access;DriverID = 25;DBQ=C:\data\train33.mdb"
- "Driver={Microsoft Access Driver (*.mdb)};DBQ=C:\Work\cvs_root\log4net-1.2\access.mdb;UID=;PWD=;"
- "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Work\cvs_root\log4net-1.2\access.mdb;User Id=;Password=;"
- System.Data.OleDb.OleDbConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
- System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
- Microsoft.Data.Odbc.OdbcConnection,Microsoft.Data.Odbc,version=1.0.3300.0,publicKeyToken=b77a5c561934e089,culture=neutral
- This is an optional package that you can download from
- http://msdn.microsoft.com/downloads
- search for ODBC .NET Data Provider.
- System.Data.OracleClient.OracleConnection, System.Data.OracleClient, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
- This is an optional package that you can download from
- http://msdn.microsoft.com/downloads
- search for .NET Managed Provider for Oracle.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- <mapping>
- <level value="ERROR" />
- <eventLogEntryType value="Error" />
- </mapping>
- <mapping>
- <level value="DEBUG" />
- <eventLogEntryType value="Information" />
- </mapping>
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- IPEndPoint remoteEndPoint = new IPEndPoint(IPAddress.Any, 0);
- UdpClient udpClient;
- byte[] buffer;
- string loggingEvent;
-
- try
- {
- udpClient = new UdpClient(8080);
-
- while(true)
- {
- buffer = udpClient.Receive(ref remoteEndPoint);
- loggingEvent = System.Text.Encoding.Unicode.GetString(buffer);
- Console.WriteLine(loggingEvent);
- }
- }
- catch(Exception e)
- {
- Console.WriteLine(e.ToString());
- }
-
-
- Dim remoteEndPoint as IPEndPoint
- Dim udpClient as UdpClient
- Dim buffer as Byte()
- Dim loggingEvent as String
-
- Try
- remoteEndPoint = new IPEndPoint(IPAddress.Any, 0)
- udpClient = new UdpClient(8080)
-
- While True
- buffer = udpClient.Receive(ByRef remoteEndPoint)
- loggingEvent = System.Text.Encoding.Unicode.GetString(buffer)
- Console.WriteLine(loggingEvent)
- Wend
- Catch e As Exception
- Console.WriteLine(e.ToString())
- End Try
-
-
-
-
-
-
-
-
-
- using log4net.Config;
- using System.IO;
- using System.Configuration;
-
- ...
-
- DOMConfigurator.Configure(new FileInfo(ConfigurationSettings.AppSettings["log4net-config-file"]));
-
-
-
-
-
-
-
-
-
- using log4net.Config;
- using System.IO;
- using System.Configuration;
-
- ...
-
- DOMConfigurator.Configure(new FileInfo(ConfigurationSettings.AppSettings["log4net-config-file"]));
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- log4net configuration XML goes here
-
-
-
-
-
-
-
-
-
- using log4net.Config;
- using System.IO;
- using System.Configuration;
-
- ...
-
- XmlConfigurator.Configure(new FileInfo(ConfigurationSettings.AppSettings["log4net-config-file"]));
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- using log4net.Config;
- using System.IO;
- using System.Configuration;
-
- ...
-
- XmlConfigurator.Configure(new FileInfo(ConfigurationSettings.AppSettings["log4net-config-file"]));
-
-
-
-
-
-
-
-
-
- ILog log = LogManager.GetLogger("application-log");
-
- log.Info("Application Start");
- log.Debug("This is a debug message");
-
- if (log.IsDebugEnabled)
- {
- log.Debug("This is another debug message");
- }
-
-
- log.Debug("This is entry number: " + i );
-
-
- if (log.IsDebugEnabled)
- {
- log.Debug("This is entry number: " + i );
- }
-
-
- private static readonly bool isDebugEnabled = log.IsDebugEnabled;
-
-
- if (isDebugEnabled)
- {
- log.Debug("This is entry number: " + i );
- }
-
-
- log.Debug("This is entry number: " + i );
-
-
- if (log.IsDebugEnabled())
- {
- log.Debug("This is entry number: " + i );
- }
-
-
- {key1=value1, key2=value2, key3=value3}
-
-
- {key1=value1, key2=value2, key3=value3}
-
-
- ILog log = LogManager.GetLogger(typeof(TestApp));
- log.Debug("Message 1");
- log.Warn("Message 2");
-
-
- DEBUG [main]: Message 1
- WARN [main]: Message 2
-
- | Format modifier | -left justify | -minimum width | -maximum width | -comment | -
|---|---|---|---|---|
| %20logger | -false | -20 | -none | -
- |
-
| %-20logger | -true | -20 | -none | -
- |
-
| %.30logger | -NA | -none | -30 | -
- |
-
| false | -20 | -30 | -
- |
- |
| %-20.30logger | -true | -20 | -30 | -
- |
-
%timestamp [%thread] %level %logger %ndc - %message%newline
- %-6timestamp [%15.15thread] %-5level %30.30logger %ndc - %message%newline
-
- StringWriter writer = new StringWriter();
- Layout.Format(writer, loggingEvent);
- string formattedEvent = writer.ToString();
-
-
- DEBUG - Hello world
-
-
- <?xml version="1.0" ?>
-
- <!DOCTYPE log4net:events SYSTEM "log4net-events.dtd" [<!ENTITY data SYSTEM "abc">]>
-
- <log4net:events version="1.2" xmlns:log4net="http://logging.apache.org/log4net/schemas/log4net-events-1.2>
- &data;
- </log4net:events>
-
-
- using log4net.Util;
-
- ILog log = LogManager.GetLogger("application-log");
-
- log.InfoExt("Application Start");
- log.DebugExt("This is a debug message");
-
-
- using(log4net.LogicalThreadContext.Stacks["NDC"].Push("Stack_Message"))
- {
- log.Warn("This should have an ThreadContext Stack message");
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- string s = OptionConverter.SubstituteVariables("Value of key is ${key}.");
-
-
- string s = OptionConverter.SubstituteVariables("Value of nonExistentKey is [${nonExistentKey}]");
-
-
- using(log4net.ThreadContext.Stacks["NDC"].Push("Stack_Message"))
- {
- log.Warn("This should have an ThreadContext Stack message");
- }
-
-
- GlobalContext.Properties["hostname"] = Environment.MachineName;
-
-
- LogicalThreadContext.Properties["user"] = userName;
- log.Info("This log message has a LogicalThreadContext Property called 'user'");
-
-
- using(LogicalThreadContext.Stacks["LDC"].Push("my context message"))
- {
- log.Info("This log message has a LogicalThreadContext Stack message that includes 'my context message'");
-
- } // at the end of the using block the message is automatically popped
-
-
- ILog log = LogManager.GetLogger("application-log");
-
- log.Info("Application Start");
- log.Debug("This is a debug message");
-
- if (log.IsDebugEnabled)
- {
- log.Debug("This is another debug message");
- }
-
-
- using(NDC.Push("my context message"))
- {
- ... all log calls will have 'my context message' included ...
-
- } // at the end of the using block the message is automatically removed
-
-
- using(log4net.NDC.Push("NDC_Message"))
- {
- log.Warn("This should have an NDC message");
- }
-
-
- var someValue = "ExampleContext"
- using(log4net.NDC.PushFormat("NDC_Message {0}", someValue))
- {
- log.Warn("This should have an NDC message");
- }
-
-
- ThreadContext.Properties["user"] = userName;
- log.Info("This log message has a ThreadContext Property called 'user'");
-
-
- using(ThreadContext.Stacks["NDC"].Push("my context message"))
- {
- log.Info("This log message has a ThreadContext Stack message that includes 'my context message'");
-
- } // at the end of the using block the message is automatically popped
-
-