本文整理汇总了C#中ILogWriter类的典型用法代码示例。如果您正苦于以下问题:C# ILogWriter类的具体用法?C# ILogWriter怎么用?C# ILogWriter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ILogWriter类属于命名空间,在下文中一共展示了ILogWriter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HttpClientContextImp
/// <summary>
/// Initializes a new instance of the <see cref="HttpClientContextImp"/> class.
/// </summary>
/// <param name="secured">true if the connection is secured (SSL/TLS)</param>
/// <param name="remoteEndPoint">client that connected.</param>
/// <param name="requestHandler">delegate handling incoming requests.</param>
/// <param name="disconnectHandler">delegate being called when a client disconnectes</param>
/// <param name="stream">Stream used for communication</param>
/// <exception cref="SocketException">If beginreceive fails</exception>
/// <param name="writer">delegate used to write log entries</param>
/// <see cref="RequestReceivedHandler"/>
/// <see cref="ClientDisconnectedHandler"/>
public HttpClientContextImp(bool secured, IPEndPoint remoteEndPoint,
RequestReceivedHandler requestHandler,
ClientDisconnectedHandler disconnectHandler,
Stream stream, ILogWriter writer)
{
Check.Require(requestHandler, "requestHandler");
Check.Require(remoteEndPoint, "remoteEndPoint");
Check.Require(remoteEndPoint.Address, "remoteEndPoint.Address");
Check.Require(stream, "stream");
if (!stream.CanWrite || !stream.CanRead)
throw new ArgumentException("Stream must be writeable and readable.");
_remoteEndPoint = remoteEndPoint;
_log = writer ?? NullLogWriter.Instance;
_parser = new HttpRequestParser(OnRequestCompleted, null);
_secured = secured;
_requestHandler = requestHandler;
_disconnectHandler = disconnectHandler;
_stream = stream;
try
{
_stream.BeginRead(_buffer, 0, BUFFER_SIZE, OnReceive, null);
}
catch (IOException err)
{
_log.Write(this, LogPrio.Debug, err.ToString());
_stream = null;
_disconnectHandler(this, SocketError.ConnectionAborted);
}
}
示例2: AsyncLogger
/// <summary>
/// Creates an asynchronous logger using the provider log writer.
/// </summary>
/// <param name="writer">The log writer that will log the log entries.</param>
public AsyncLogger(ILogWriter writer)
{
if (writer == null)
throw new ArgumentNullException(nameof(writer));
this.writer = writer;
}
示例3: RunTarget
public MSBuildResult[] RunTarget (string target, ProjectConfigurationInfo[] configurations, ILogWriter logWriter,
MSBuildVerbosity verbosity)
{
MSBuildResult[] result = null;
BuildEngine.RunSTA (delegate
{
try {
var project = SetupProject (configurations);
currentLogWriter = logWriter;
var logger = new LocalLogger (file);
buildEngine.Engine.UnregisterAllLoggers ();
buildEngine.Engine.RegisterLogger (logger);
buildEngine.Engine.RegisterLogger (consoleLogger);
consoleLogger.Verbosity = GetVerbosity (verbosity);
// We are using this BuildProject overload and the BuildSettings.None argument as a workaround to
// an xbuild bug which causes references to not be resolved after the project has been built once.
buildEngine.Engine.BuildProject (project, new [] { target }, new Hashtable (), BuildSettings.None);
result = logger.BuildResult.ToArray ();
} catch (InvalidProjectFileException ex) {
var r = new MSBuildResult (
file, false, ex.ErrorSubcategory, ex.ErrorCode, ex.ProjectFile,
ex.LineNumber, ex.ColumnNumber, ex.EndLineNumber, ex.EndColumnNumber,
ex.BaseMessage, ex.HelpKeyword);
logWriter.WriteLine (r.ToString ());
result = new [] { r };
} finally {
currentLogWriter = null;
}
});
return result;
}
示例4: HttpClientContext
/// <summary>
/// Initializes a new instance of the <see cref="HttpClientContext"/> class.
/// </summary>
/// <param name="secured">true if the connection is secured (SSL/TLS)</param>
/// <param name="remoteEndPoint">client that connected.</param>
/// <param name="stream">Stream used for communication</param>
/// <param name="parserFactory">Used to create a <see cref="IHttpRequestParser"/>.</param>
/// <param name="bufferSize">Size of buffer to use when reading data. Must be at least 4096 bytes.</param>
/// <exception cref="SocketException">If <see cref="Socket.BeginReceive(byte[],int,int,SocketFlags,AsyncCallback,object)"/> fails</exception>
/// <exception cref="ArgumentException">Stream must be writable and readable.</exception>
public HttpClientContext(bool secured, IPEndPoint remoteEndPoint,
Stream stream, IRequestParserFactory parserFactory, int bufferSize, Socket sock, ILogWriter log)
{
Check.Require(remoteEndPoint, "remoteEndPoint");
Check.NotEmpty(remoteEndPoint.Address.ToString(), "remoteEndPoint.Address");
Check.Require(stream, "stream");
Check.Require(parserFactory, "parser");
Check.Min(4096, bufferSize, "bufferSize");
Check.Require(sock, "socket");
if (!stream.CanWrite || !stream.CanRead)
throw new ArgumentException("Stream must be writable and readable.");
_bufferSize = bufferSize;
RemoteAddress = remoteEndPoint.Address.ToString();
RemotePort = remoteEndPoint.Port.ToString();
_log = log;
_parser = parserFactory.CreateParser(_log);
_parser.RequestCompleted += OnRequestCompleted;
_parser.RequestLineReceived += OnRequestLine;
_parser.HeaderReceived += OnHeaderReceived;
_parser.BodyBytesReceived += OnBodyBytesReceived;
_currentRequest = new HttpRequest();
IsSecured = secured;
if (stream == null)
throw new NullReferenceException ("Null Stream in HttpClientContext");
_stream = stream;
_buffer = new byte[bufferSize];
}
示例5: UnregisterLogWriter
public void UnregisterLogWriter(ILogWriter logWriter)
{
lock (SyncroObject)
{
LogWriters.Remove(logWriter);
}
}
示例6: DefaultRackServer
public DefaultRackServer(int port,IPAddress ipAddress,ILogWriter logWriter)
{
_server = new HttpServer.HttpServer(logWriter);
_ipAddress = ipAddress;
_port = port;
_logWriter = logWriter;
}
示例7: RunTarget
public MSBuildResult[] RunTarget (string target, ProjectConfigurationInfo[] configurations, ILogWriter logWriter,
MSBuildVerbosity verbosity)
{
MSBuildResult[] result = null;
BuildEngine.RunSTA (delegate
{
try {
var project = SetupProject (configurations);
currentLogWriter = logWriter;
var logger = new LocalLogger (file);
engine.UnregisterAllLoggers ();
engine.RegisterLogger (logger);
engine.RegisterLogger (consoleLogger);
consoleLogger.Verbosity = GetVerbosity (verbosity);
project.Build (target);
result = logger.BuildResult.ToArray ();
} catch (Microsoft.Build.Exceptions.InvalidProjectFileException ex) {
var r = new MSBuildResult (
file, false, ex.ErrorSubcategory, ex.ErrorCode, ex.ProjectFile,
ex.LineNumber, ex.ColumnNumber, ex.EndLineNumber, ex.EndColumnNumber,
ex.BaseMessage, ex.HelpKeyword);
logWriter.WriteLine (r.ToString ());
result = new [] { r };
} finally {
currentLogWriter = null;
}
});
return result;
}
示例8: AddLogWriter
/// <summary>
/// Adds a log writer and binds to a specific log message type
/// </summary>
/// <param name="logMessageType">Type of log message</param>
/// <param name="logWriter">Log writer to add</param>
public void AddLogWriter(NiawaLogType logMessageType, ILogWriter logWriter)
{
//Ensure that more than one instance of a ILogWriter implementation (of a specific type) is not added.
if(_logWriters.ContainsKey(logWriter.GetType().ToString()))
if (_logWriters[logWriter.GetType().ToString()].LogWriterID != logWriter.LogWriterID)
throw new Exception("Cannot add two instances of the same ILogWriter type [" + logWriter.GetType().ToString() + "]. Add a different type of ILogWriter, or add an existing instance of this ILogWriter type.");
//Check for duplicate entry attempts into the LogMessageTypeLogWriters collection
if (_logMessageTypeLogWriters.ContainsKey(logMessageType))
if (_logMessageTypeLogWriters[logMessageType].Contains(logWriter))
throw new Exception("Cannot add the same ILogWriter [" + logWriter.GetType().ToString() + "] for LogMessageType [" + Enum.GetName(logMessageType.GetType(), logMessageType) + "] more than once.");
//add log writer to list
if (!(_logWriters.ContainsKey(logWriter.GetType().ToString())))
_logWriters.Add(logWriter.GetType().ToString(), logWriter);
//add log writer to map
List<ILogWriter> mapLogWriters = null;
//check if log message type already in map
if (_logMessageTypeLogWriters.ContainsKey(logMessageType))
mapLogWriters = _logMessageTypeLogWriters[logMessageType];
else
{
//create new entry of log writers for log message type and add to map
mapLogWriters = new List<ILogWriter>();
_logMessageTypeLogWriters.Add(logMessageType, mapLogWriters);
}
//add log writer to list of log writers mapped to log message type
mapLogWriters.Add(logWriter);
}
示例9: AutomaticMigration
public AutomaticMigration(IAccessDb db, IManageMigrations migrations, ILogWriter logger)
{
_db = db;
_migrations = migrations;
_runner=new MigrationTaskRunner(db,logger);
UpdateSelf();
}
示例10: Attach
public void Attach(ILogWriter newLogWriter)
{
if (newLogWriter == null)
throw new ArgumentNullException("newLogWriter");
if (newLogWriter == this.WrappedLogWriter)
return;
ILogWriter prevLogWriter = this.WrappedLogWriter;
Exception detachException = null;
if (this.WrappedLogWriter != null)
{
try
{
prevLogWriter.Detach();
}
catch (Exception ex)
{
detachException = ex;
}
this.WrappedLogWriter.ServerWriteLine(
string.Format("Log writer \"{0}\" is being detached.", this.LogWriterName), TraceLevel.Verbose);
}
this.WrappedLogWriter = newLogWriter;
this.WrappedLogWriter.ServerWriteLine(
string.Format("Log writer \"{0}\" has been attached.", this.LogWriterName), TraceLevel.Verbose);
if (detachException != null)
this.ServerWriteLine(
string.Format("Log writer \"{0}\" had thrown an unexpected exception:\n{1}", prevLogWriter.Name, detachException),
TraceLevel.Error);
}
示例11: RunTarget
public MSBuildResult[] RunTarget (string target, ProjectConfigurationInfo[] configurations, ILogWriter logWriter,
MSBuildVerbosity verbosity)
{
MSBuildResult[] result = null;
BuildEngine.RunSTA (delegate
{
try {
var project = SetupProject (configurations);
currentLogWriter = logWriter;
LocalLogger logger = new LocalLogger (Path.GetDirectoryName (file));
engine.UnregisterAllLoggers ();
engine.RegisterLogger (logger);
engine.RegisterLogger (consoleLogger);
consoleLogger.Verbosity = GetVerbosity (verbosity);
project.Build (target);
result = logger.BuildResult.ToArray ();
// } catch (InvalidProjectFileException ex) {
// result = new MSBuildResult[] { new MSBuildResult (false, ex.ProjectFile ?? file, ex.LineNumber, ex.ColumnNumber, ex.ErrorCode, ex.Message) };
} finally {
currentLogWriter = null;
}
});
return result;
}
示例12: DatabaseFactory
public DatabaseFactory(IConnectionString connectionString, ILogWriter logWriter)
{
Checks.Argument.IsNotNull(connectionString, "connectionString");
_connectionString = connectionString.Value;
_logWriter = logWriter;
}
示例13: RegisterLogWriter
public void RegisterLogWriter(ILogWriter logWriter)
{
lock (SyncroObject)
{
LogWriters.Add(logWriter);
}
}
示例14: HttpContextFactory
/// <summary>
/// Initializes a new instance of the <see cref="HttpContextFactory"/> class.
/// </summary>
/// <param name="writer">The writer.</param>
/// <param name="bufferSize">Amount of bytes to read from the incoming socket stream.</param>
/// <param name="factory">Used to create a request parser.</param>
public HttpContextFactory(ILogWriter writer, int bufferSize, IRequestParserFactory factory)
{
_logWriter = writer;
_bufferSize = bufferSize;
_factory = factory;
_contextTimeoutManager = new ContextTimeoutManager(ContextTimeoutManager.MonitorType.Thread);
}
示例15: Run
public MSBuildResult Run (
ProjectConfigurationInfo[] configurations, ILogWriter logWriter, MSBuildVerbosity verbosity,
string[] runTargets, string[] evaluateItems, string[] evaluateProperties)
{
MSBuildResult result = null;
BuildEngine.RunSTA (delegate {
try {
var project = SetupProject (configurations);
currentLogWriter = logWriter;
buildEngine.Engine.UnregisterAllLoggers ();
var logger = new LocalLogger (file);
buildEngine.Engine.RegisterLogger (logger);
if (logWriter != null) {
buildEngine.Engine.RegisterLogger (consoleLogger);
consoleLogger.Verbosity = GetVerbosity (verbosity);
}
if (runTargets != null && runTargets.Length > 0) {
// We are using this BuildProject overload and the BuildSettings.None argument as a workaround to
// an xbuild bug which causes references to not be resolved after the project has been built once.
buildEngine.Engine.BuildProject (project, runTargets, new Hashtable (), BuildSettings.None);
}
result = new MSBuildResult (logger.BuildResult.ToArray ());
if (evaluateProperties != null) {
foreach (var name in evaluateProperties)
result.Properties [name] = project.GetEvaluatedProperty (name);
}
if (evaluateItems != null) {
foreach (var name in evaluateItems) {
BuildItemGroup grp = project.GetEvaluatedItemsByName (name);
var list = new List<MSBuildEvaluatedItem> ();
foreach (BuildItem item in grp) {
var evItem = new MSBuildEvaluatedItem (name, UnescapeString (item.FinalItemSpec));
foreach (DictionaryEntry de in (IDictionary) evaluatedMetadataField.GetValue (item)) {
evItem.Metadata [(string)de.Key] = UnescapeString ((string)de.Value);
}
list.Add (evItem);
}
result.Items[name] = list;
}
}
} catch (InvalidProjectFileException ex) {
var r = new MSBuildTargetResult (
file, false, ex.ErrorSubcategory, ex.ErrorCode, ex.ProjectFile,
ex.LineNumber, ex.ColumnNumber, ex.EndLineNumber, ex.EndColumnNumber,
ex.BaseMessage, ex.HelpKeyword);
logWriter.WriteLine (r.ToString ());
result = new MSBuildResult (new [] { r });
} finally {
currentLogWriter = null;
}
});
return result;
}