我有一个应用程序。在调试过程中,我将重要信息记录到文件或交互界面中。
这是示例:
您会看到第一行日志信息没有线程名称。我想添加一个名字。但是哪里?
public static void Start()
{
lock (SyncVar)
{
if (State == State.Stopped)
{
s_State = State.Starting;
ThreadStart ts = new ThreadStart(MainCode);
s_MainCodeThread = new Thread(ts);
s_MainCodeThread.Name = "IvrApplication";
s_MainCodeThread.Start();
Log.Write("IvrApplication Starting...");
}
和....
public static void MainCode()
{
try
{
s_WorkingFolder = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
Log.Write("IvrApplication::MainCode() Starting...");
// Start Other Threads...
try
{
至于日志,我们有
private static Log s_Log;
public static Log Log
{
get { return s_Log; }
}
实际上日志来自一个dll
这是部分元数据。
namespace VoiceElements.Common
{
public class Log
{
[ThreadStatic]
public static string Identifier1;
[ThreadStatic]
public static string Identifier2;
public int LogLevel;
public Log(string logname);
public bool AlwaysExpanded { get; set; }
public event MessageLogged MessageLogged;
public void CloseLog();
public void Write(string LogEntry);