本文整理匯總了C#中System.Log類的典型用法代碼示例。如果您正苦於以下問題:C# Log類的具體用法?C# Log怎麽用?C# Log使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Log類屬於System命名空間,在下文中一共展示了Log類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Init
public override bool Init(Main Main, System.Diagnostics.Stopwatch swInit)
{
if (!Main.EventMgr.PluginExists<Events.System>())
{
this.Log.LogLine("Task \"LogSystemEvents\" is missing EventPlugin \"System\"!", Log.Type.Error);
return false;
}
this.Main = Main;
this.Log = Main.Log;
swInit.Stop();
Events.System sysEvents = Main.EventMgr.GetPlugin<Events.System>();
swInit.Start();
sysEvents.InstalledFontsChanged += new Events.EventPlugin.Event(sysEvents_InstalledFontsChanged);
sysEvents.FontAdded += new Events.EventPlugin.EventValue<FontFamily>(sysEvents_FontAdded);
sysEvents.FontRemoved += new Events.EventPlugin.EventValue<FontFamily>(sysEvents_FontRemoved);
sysEvents.Logoff += new Events.EventPlugin.Event(sysEvents_Logoff);
sysEvents.Shutdown += new Events.EventPlugin.Event(sysEvents_Shutdown);
sysEvents.ConsoleConnect += new Events.EventPlugin.Event(sysEvents_ConsoleConnect);
sysEvents.ConsoleDisconnect += new Events.EventPlugin.Event(sysEvents_ConsoleDisconnect);
sysEvents.RemoteConnect += new Events.EventPlugin.Event(sysEvents_RemoteConnect);
sysEvents.RemoteDisconnect += new Events.EventPlugin.Event(sysEvents_RemoteDisconnect);
sysEvents.SessionLock += new Events.EventPlugin.Event(sysEvents_SessionLock);
sysEvents.SessionLogoff += new Events.EventPlugin.Event(sysEvents_SessionLogoff);
sysEvents.SessionLogon += new Events.EventPlugin.Event(sysEvents_SessionLogon);
sysEvents.SessionRemoteControl += new Events.EventPlugin.Event(sysEvents_SessionRemoteControl);
sysEvents.SessionUnlock += new Events.EventPlugin.Event(sysEvents_SessionUnlock);
return true;
}
示例2: OnActionExecuting
/// <summary>
/// 檢查用戶是否有該Action執行的操作權限
/// </summary>
/// <param name="actionContext"></param>
public override void OnActionExecuting(HttpActionContext actionContext)
{
//增加操作日誌
var log = new Log()
{
Action = $"{actionContext.ControllerContext.ControllerDescriptor.ControllerName}/{actionContext.ActionDescriptor.ActionName}",
Note = GetText(actionContext.ActionArguments)
};
var b = actionContext.Request.Headers.Referrer;
var attr = actionContext.ActionDescriptor.GetCustomAttributes<AllowAnonymousAttribute>();
if (attr.Any(a => a != null))//判斷是否允許匿名調用
{
base.OnActionExecuting(actionContext);
}
else if (b != null && CfgLoader.Instance.GetArraryConfig<string>("Csrf", "Address").Any(r => b.ToString().StartsWith(r)))
{
AuthFrom(actionContext, ref log);
}
else if (b == null)
{
actionContext.Response = new HttpResponseMessage(HttpStatusCode.Unauthorized);
}
base.OnActionExecuting(actionContext);
log.Save(Guid.Empty);
}
示例3: WriteLineTest
public void WriteLineTest()
{
var logFilename = Path.Combine(_logFileDirectory, "logtest.txt");
using (var sw = new StreamWriter(logFilename))
{
var log = new Log(sw);
log.WriteLine(LogEntryType.Info, "info log entry");
log.WriteLine(LogEntryType.Warning, "warning log entry");
log.WriteLine(LogEntryType.Error, "error log entry");
}
var logFileContents = File.ReadAllLines(logFilename);
/*
Log entries look like this:
2013-01-26T02:00:26.3637578Z - INF - Hello, world!
2013-01-26T02:00:26.3793828Z - WRN - Hello, world!
2013-01-26T02:00:26.3793828Z - ERR - Hello, world!
*/
Assert.IsTrue(this.DoesMatchLogEntryFormat(logFileContents[0], "INF", "info log entry"), logFileContents[0]);
Assert.IsTrue(this.DoesMatchLogEntryFormat(logFileContents[1], "WRN", "warning log entry"), logFileContents[1]);
Assert.IsTrue(this.DoesMatchLogEntryFormat(logFileContents[2], "ERR", "error log entry"), logFileContents[2]);
}
示例4: ClientInputProcessor
public ClientInputProcessor(INetworkPlayerProcessor networkPlayerProcessor, Log<ChatMessage> serverChatLog, IClientStateTracker clientStateTracker, IIncomingMessageQueue incomingMessageQueue)
{
this.NetworkPlayerProcessor = networkPlayerProcessor;
this.ServerChatLog = serverChatLog;
this.ClientStateTracker = clientStateTracker;
this.IncomingMessageQueue = incomingMessageQueue;
}
示例5: Logger
// 로그를 출력합니다.
public void Logger(Log type, string format, params Object[] args)
{
string message = String.Format(format, args);
switch (type)
{
case Log.조회:
lst조회.Items.Add(message);
lst조회.SelectedIndex = lst조회.Items.Count - 1;
break;
case Log.에러:
lst에러.Items.Add(message);
lst에러.SelectedIndex = lst에러.Items.Count - 1;
break;
case Log.일반:
lst일반.Items.Add(message);
lst일반.SelectedIndex = lst일반.Items.Count - 1;
break;
case Log.실시간:
lst실시간.Items.Add(message);
lst실시간.SelectedIndex = lst실시간.Items.Count - 1;
break;
default:
break;
}
}
示例6: CommandConsole
public CommandConsole(IMediator mediator, Log<string> commandLog)
{
_mediator = mediator;
Active = false;
Log = commandLog;
}
示例7: TestConcurrency
public void TestConcurrency()
{
// start up the next log instance
var queue = new Loggers.Queue();
var props = new List<String>()
{
"Request.Duration"
};
using (
Log.RegisterInstance(
new Instance()
{
Logger = queue,
Synchronous = false,
Buffer = 0,
Properties = props
}
)
)
{
Log log = new Log(GetType());
Parallel.For(0, TestParallelIterations,
i => new MockHttp.Application().DispatchRequest()
);
Log.Flush();
// verify event properties
for (Int32 i = 0; i < TestParallelIterations; i++)
{
var evt = queue.Dequeue().First();
Assert.IsTrue((Int64)evt["Request.Duration"] > 0);
Assert.IsTrue((Int64)evt["Request.Duration"] < 10000000);
}
Assert.IsFalse(queue.Dequeue().Any());
}
}
示例8: LoglamaDogruCalisiyorMu
public void LoglamaDogruCalisiyorMu()
{
LogManager manager = LogManager.CreateInstance(new TestConfigReader("DAI.Log,DAI.Log.TraceLogger", "DAI.Log,DAI.Log.HtmlLogFormatter"));
Log myLog = new Log("Deneme mesaj", LogPriority.Normal, DateTime.Now);
bool result = manager.WriteLog(myLog);
Assert.AreEqual(result, true);
}
示例9: Init
public override bool Init(Main Main, System.Diagnostics.Stopwatch swInit)
{
if (!Main.EventMgr.PluginExists<Events.Screen>())
{
this.Log.LogLine("Task \"LogScreenEvents\" is missing EventPlugin \"Screen\"!", Log.Type.Error);
return false;
}
this.Main = Main;
this.Log = Main.Log;
swInit.Stop();
Events.Screen screenEvents = Main.EventMgr.GetPlugin<Events.Screen>();
swInit.Start();
screenEvents.ScreenAdded += new Events.EventPlugin.EventValue<ScreenEx>(screenEvents_ScreenAdded);
screenEvents.ScreenRemoved += new Events.EventPlugin.EventValue<ScreenEx>(screenEvents_ScreenRemoved);
screenEvents.ScreenColorDepthChanged += new Events.EventPlugin.EventValues<ScreenEx>(screenEvents_ScreenColorDepthChanged);
screenEvents.ScreenResolutionChanged += new Events.EventPlugin.EventValues<ScreenEx>(screenEvents_ScreenResolutionChanged);
screenEvents.PrimaryScreenChanged += new Events.EventPlugin.EventValues<ScreenEx>(screenEvents_PrimaryScreenChanged);
screenEvents.ScreenLocationChanged += new Events.EventPlugin.EventValues<ScreenEx>(screenEvents_ScreenLocationChanged);
screenEvents.ScreenOrientationChanged += new Events.EventPlugin.EventValues<ScreenEx>(screenEvents_ScreenOrientationChanged);
screenEvents.ScreenRefreshRateChanged += new Events.EventPlugin.EventValues<ScreenEx>(screenEvents_ScreenRefreshRateChanged);
return true;
}
示例10: GetLog
public Log GetLog(int LoggerId)
{
Log oLog = new Log();
DbCommand oDbCommand = DbProviderHelper.CreateCommand("SELECTLog",CommandType.StoredProcedure);
oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@LoggerId",DbType.Int32,LoggerId));
DbDataReader oDbDataReader = DbProviderHelper.ExecuteReader(oDbCommand);
while (oDbDataReader.Read())
{
oLog.LoggerId = Convert.ToInt32(oDbDataReader["LoggerId"]);
if(oDbDataReader["LoggerGuid"] != DBNull.Value)
oLog.LoggerGuid = (Guid) oDbDataReader["LoggerGuid"];
if(oDbDataReader["UserGuid"] != DBNull.Value)
oLog.UserGuid = (Guid) oDbDataReader["UserGuid"];
if(oDbDataReader["Title"] != DBNull.Value)
oLog.Title = Convert.ToString(oDbDataReader["Title"]);
oLog.SubmissionGuid = (Guid) oDbDataReader["SubmissionGuid"];
if(oDbDataReader["Message"] != DBNull.Value)
oLog.Message = Convert.ToString(oDbDataReader["Message"]);
oLog.DateCreated = Convert.ToDateTime(oDbDataReader["DateCreated"]);
}
oDbDataReader.Close();
return oLog;
}
示例11: Insert
public static Log Insert(Log myItem)
{
using (MySqlConnection myConnection = new MySqlConnection(Param.MySQLConnectionString))
{
StringBuilder mySql = new StringBuilder();
mySql.Append("INSERT INTO `Log` ");
mySql.Append("(`idProjet`, `libelle`, ");
mySql.Append("`cheminFichier`, commentaire )");
mySql.Append(" VALUES ");
mySql.Append("(@idProjet, @libelle, ");
mySql.Append("@cheminFichier, @commentaire );");
mySql.Append("SELECT LAST_INSERT_ID(); ");
MySqlCommand myCommand = new MySqlCommand(mySql.ToString(), myConnection);
myCommand.CommandType = CommandType.Text;
myCommand.Parameters.AddWithValue("@idProjet", myItem.idProjet);
myCommand.Parameters.AddWithValue("@libelle", myItem.libelle);
myCommand.Parameters.AddWithValue("@cheminFichier", myItem.cheminFichier);
myCommand.Parameters.AddWithValue("@commentaire", myItem.commentaire);
myConnection.Open();
myItem.id = iZyMySQL.GetIntFromDBInt(myCommand.ExecuteScalar());
myConnection.Close();
}
return myItem;
}
示例12: log
void log(Log.Severity severity, string str)
{
using (Log.pushContext(_name))
{
Log.log(severity, str);
}
}
示例13: TestMethod1
public void TestMethod1()
{
LogDAL dal = new LogDAL();
Log log = new Log { Thread = "1", Exception = "Test", Description = "test", Time = DateTime.Now };
int result = dal.Insert(log);
Console.WriteLine(result);
}
示例14: Init
public override bool Init(Main Main, System.Diagnostics.Stopwatch swInit)
{
if (!Main.EventMgr.PluginExists<Events.Power>())
{
this.Log.LogLine("Task \"LogPowerEvents\" is missing EventPlugin \"Power\"!", Log.Type.Error);
return false;
}
this.Main = Main;
this.Log = Main.Log;
swInit.Stop();
Events.Power pwrEvents = Main.EventMgr.GetPlugin<Events.Power>(new object[] {Main}, true);
swInit.Start();
pwrEvents.PowerModeChanged += new Events.EventPlugin.EventValue<PowerModes>(pwrEvents_PowerModeChanged);
pwrEvents.Suspend += new Events.EventPlugin.Event(pwrEvents_Suspend);
pwrEvents.Resume += new Events.EventPlugin.Event(pwrEvents_Resume);
pwrEvents.PowerLineStatusChanged += new Events.EventPlugin.EventValues<PowerLineStatus>(pwrEvents_PowerLineStatusChanged);
pwrEvents.BatteryAvailabilityChanged += new Events.EventPlugin.EventValue<bool?>(pwrEvents_BatteryAvailabilityChanged);
pwrEvents.BatteryStatusChanged += new Events.EventPlugin.EventValues<BatteryChargeStatus>(pwrEvents_BatteryStatusChanged);
pwrEvents.PowerSchemeChanged += new Events.EventPlugin.EventValues<PowerScheme>(pwrEvents_PowerSchemeChanged);
return true;
}
示例15: CloseApplicationViaFileExitMenuItem
/// <summary>
/// Closes the application via the 'File - Exit' menu.
/// </summary>
/// <param name="application">The application.</param>
/// <param name="log">The log object.</param>
/// <exception cref="RegressionTestFailedException">
/// Thrown if the 'File - Exit' menu could not be invoked for some reason.
/// </exception>
public static void CloseApplicationViaFileExitMenuItem(Application application, Log log)
{
const string prefix = "Menus - Close application via File menu";
var menu = GetMainMenu(application, log);
if (menu == null)
{
throw new RegressionTestFailedException(prefix + ": Failed to get the main menu.");
}
var fileMenuSearchCriteria = SearchCriteria.ByAutomationId(MainMenuAutomationIds.File);
var exitSearchCriteria = SearchCriteria.ByAutomationId(MainMenuAutomationIds.FileExit);
var exitMenu = Retry.Times(() => menu.MenuItemBy(fileMenuSearchCriteria, exitSearchCriteria));
if (exitMenu == null)
{
throw new RegressionTestFailedException(prefix + ": Failed to get the 'File - Exit' menu.");
}
try
{
exitMenu.Click();
application.Process.WaitForExit(Constants.ShutdownWaitTimeInMilliSeconds());
}
catch (Exception e)
{
throw new RegressionTestFailedException(prefix + ": Failed to click the 'File - Exit' menu item.", e);
}
}