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;
...
XmlConfigurator.Configure(new FileInfo(ConfigurationSettings.AppSettings["log4net-config-file"]));
log.Debug("This is entry number: " + i );
if (log.IsDebugEnabled())
{
log.Debug("This is entry number: " + i );
}
GlobalContext.Properties["hostname"] = Environment.MachineName;
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 );
}
StringWriter writer = new StringWriter();
Layout.Format(writer, loggingEvent);
string formattedEvent = writer.ToString();
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
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>
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
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}]");
{key1=value1, key2=value2, key3=value3}
{key1=value1, key2=value2, key3=value3}
using(log4net.ThreadContext.Stacks["NDC"].Push("Stack_Message"))
{
log.Warn("This should have an ThreadContext Stack message");
}