November 21, 2005

Modifying Config File for a Log4Net TraceAppender

Modifying an App.Config file for Log4Net Adding a TraceAppender:
  <appender name="TraceAppender" type="log4net.Appender.TraceAppender">
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%date{HH:mm:ss,fff}[%thread] %-5level %logger{2}:    

   %message%newline%exception" />
  </layout>
  </appender>
Setting a module to use the log to the TraceAppender and the ConsoleAppender
  <logger name="mymodule.comms">
    <level value="ALL" />
      <appender-ref ref="ConsoleAppender" />
  <appender-ref ref="TraceAppender" />
  </logger>

Helper Class To Converts Strings To Ascii and Back

using System.Text;

...

// Helper methods for converting strings to ascii and back
public class Ascii
{
 // Converts a standard c# unicode string to an array of ASCII characters
 public static byte[] FromString(string str)
 {
  Encoding ascii = Encoding.ASCII;
  byte[] asciiBytes = ascii.GetBytes(str);
  return asciiBytes;
 }

 // Converts an array of ASCII characters to a standard c# unicode string 
 public static string ToString(byte[] asciiString)
 {
  // Create two different encodings.
  Encoding ascii = Encoding.ASCII;
  string str = ascii.GetString(asciiString);
  return str;
 }
}

Using Streams To Serialize Something to A Byte Array

Writing To A Stream Using A BinaryWriter
byte[] data;
MemoryStream stream = new MemoryStream();
BitWriter writer = new BitWriter(stream, System.Text.Encoding.ASCII);
writer.UseNetworkByteOrder = true;
bat.Serialize(writer);
stream.Flush();
stream.Close();
data = stream.ToArray();
return data;

TCP/IP Socket Programming in C#

Here is some links I discovered during my research: