Permalink
Browse files

fix ConsoleTraceListner Sequential.

add option value logging
  • Loading branch information...
darkcrash committed Jan 11, 2016
1 parent 7cf4ada commit ebab35aad61cd85f66234f0c0b1a670739a7c915
@@ -295,8 +295,19 @@ public void Set(LogKind logKind, SockObj sockBase, int messageNo, String detailI
var remoteHostname = (sockBase == null) ? "-" : sockBase.RemoteHostname;
var oneLog = new OneLog(DateTime.Now, logKind, _nameTag, threadId, remoteHostname, messageNo, message,
detailInfomation);
switch (logKind)
{
case LogKind.Error:
System.Diagnostics.Trace.TraceError($"{oneLog.ToString()}");
break;
case LogKind.Secure:
System.Diagnostics.Trace.TraceWarning($"{oneLog.ToString()}");
break;
default:
System.Diagnostics.Trace.TraceInformation($"{oneLog.ToString()}");
break;
}
System.Diagnostics.Trace.TraceInformation($"{oneLog.ToString()}");
// 表示制限にヒットするかどうかの確認
var isDisplay = true;
@@ -132,7 +132,7 @@ public bool FromReg(String str)
{
throw;
}
System.Diagnostics.Trace.TraceInformation($"{this.Name}={this.Value}");
return true;
}
@@ -8,6 +8,7 @@ namespace Bjd.trace
{
public class ConsoleTraceListner : System.Diagnostics.TraceListener
{
SequentialTaskScheduler sts = new SequentialTaskScheduler();
public ConsoleTraceListner()
{
@@ -127,14 +128,78 @@ public override void TraceEvent(TraceEventCache eventCache, string source, Trace
sb.Append($"[{id}] ");
sb.Append(new string(' ', this.IndentLevel * this.IndentSize));
sb.Append(message);
this.WriteLine(sb.ToString());
Console.WriteLine(sb.ToString());
//base.TraceEvent(eventCache, source, eventType, id, message);
};
var t = new Task(tAct, TaskCreationOptions.PreferFairness);
t.Start();
t.Start(this.sts);
}
}
class SequentialTaskScheduler : System.Threading.Tasks.TaskScheduler
{
List<Task> _q = new List<Task>();
object Lock = new object();
bool isRunning = false;
public SequentialTaskScheduler() : base()
{
}
private void WaitCallback(object state)
{
Task t;
while (true)
{
lock (Lock)
{
if (_q.Count == 0)
{
isRunning = false;
return;
}
t = _q.First();
_q.Remove(t);
}
this.TryExecuteTask(t);
}
}
protected override IEnumerable<Task> GetScheduledTasks()
{
return _q.ToArray();
}
protected override void QueueTask(Task task)
{
lock (Lock)
{
_q.Add(task);
if (isRunning)
return;
isRunning = true;
System.Threading.ThreadPool.QueueUserWorkItem(this.WaitCallback);
}
}
protected override bool TryExecuteTaskInline(Task task, bool taskWasPreviouslyQueued)
{
return false;
}
protected override bool TryDequeue(Task task)
{
lock (Lock)
{
return _q.Remove(task);
}
}
public override int MaximumConcurrencyLevel
{
get
{
return 1;
}
}
}
}

0 comments on commit ebab35a

Please sign in to comment.