本文整理汇总了C#中log4net.Core.Level.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# Level.ToString方法的具体用法?C# Level.ToString怎么用?C# Level.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类log4net.Core.Level
的用法示例。
在下文中一共展示了Level.ToString方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetLoggingLevel
/// <summary>
/// Sets logging level for all current loggers to the level provided in arguments.
/// Note: use it only when you need more control on logging, e.g. in unit tests. Otherwise use configuration files.
/// </summary>
/// <param name="level"></param>
public static void SetLoggingLevel(Level level)
{
var repositories = LogManager.GetAllRepositories();
//Configure all loggers to be at the debug level.
foreach (var repository in repositories)
{
repository.Threshold = repository.LevelMap[level.ToString()];
var hierarchy = (log4net.Repository.Hierarchy.Hierarchy)repository;
var loggers = hierarchy.GetCurrentLoggers();
foreach (var logger in loggers)
{
((log4net.Repository.Hierarchy.Logger)logger).Level = hierarchy.LevelMap[level.ToString()];
}
}
//Configure the root logger.
var h = (log4net.Repository.Hierarchy.Hierarchy)log4net.LogManager.GetRepository();
var rootLogger = h.Root;
rootLogger.Level = h.LevelMap[level.ToString()];
}
示例2: RemoveMatchingLogEntries
public static void RemoveMatchingLogEntries(Level level, string message, string application)
{
string commandText = String.Format("DELETE FROM dbo.Log4Net WHERE Level = @Level AND Message = @Message AND Application = @Application");
using (SqlConnection sqlConnection = new SqlConnection(ConnectionString))
{
sqlConnection.Open();
using (SqlCommand sqlCommand = new SqlCommand(commandText, sqlConnection))
{
sqlCommand.Parameters.Add(new SqlParameter("Level", level.ToString()));
sqlCommand.Parameters.Add(new SqlParameter("Message", message));
sqlCommand.Parameters.Add(new SqlParameter("Application", application));
sqlCommand.ExecuteNonQuery();
}
}
}
示例3: CountLogEntriesPresent
public static int CountLogEntriesPresent(Level level, string message, string application)
{
string commandText = String.Format("SELECT COUNT(*) FROM dbo.Log4Net (nolock) WHERE Level = @Level AND Message = @Message AND Application = @Application");
using (SqlConnection sqlConnection = new SqlConnection(ConnectionString))
{
sqlConnection.Open();
using (SqlCommand sqlCommand = new SqlCommand(commandText, sqlConnection))
{
sqlCommand.Parameters.Add(new SqlParameter("Level", level.ToString()));
sqlCommand.Parameters.Add(new SqlParameter("Message", message));
sqlCommand.Parameters.Add(new SqlParameter("Application", application));
int rowCount = (int)sqlCommand.ExecuteScalar();
return rowCount;
}
}
}
示例4: IsLogEntryPresent
public static bool IsLogEntryPresent(Level level, string message, string application)
{
string commandText = String.Format("SELECT * FROM dbo.Log4Net WHERE Level = @Level AND Message = @Message AND Application = @Application");
using (SqlConnection sqlConnection = new SqlConnection(ConnectionString))
{
sqlConnection.Open();
using (SqlCommand sqlCommand = new SqlCommand(commandText, sqlConnection))
{
sqlCommand.Parameters.Add(new SqlParameter("Level", level.ToString()));
sqlCommand.Parameters.Add(new SqlParameter("Message", message));
sqlCommand.Parameters.Add(new SqlParameter("Application", application));
SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
int fieldCount = 0;
while (sqlDataReader.Read())
{
fieldCount++;
}
return fieldCount == 1;
}
}
}
示例5: CreateSelectItem
private static SelectListItem CreateSelectItem(Level level)
{
SelectListItem sel = new SelectListItem();
sel.Text = level.DisplayName;
sel.Value = level.ToString();
return sel;
}
示例6: GetLevelName
private static string GetLevelName(Level code)
{
return string.Format("Log{0}", code.ToString()).ToLower();
}
示例7:
void ILogger.Log(Type callerStackBoundaryDeclaringType, Level level, object message, Exception exception)
{
tbLog.Text += string.Format("{0} - {1}, {2}", level.ToString(),message.ToString(), exception.ToString());
}
示例8: LogToFile
internal static void LogToFile(string logFile, string message, Level level, string category, Exception exception)
{
string formatedMessage = null;
if (exception == null)
{
formatedMessage = String.Format("{0} {1,-5} {2,-8} - {3}", new object[]{
DateTime.Now.ToString("MM-dd HH:mm:ss.fff"),
level.ToString(),
category,
message
});
}
else if (!String.IsNullOrEmpty(message))
{
formatedMessage = String.Format("{0} {1,-5} {2,-8} - {3}\r\n{4}", new object[]{
DateTime.Now.ToString("MM-dd HH:mm:ss.fff"),
level.ToString(),
category,
message,
exception.ToString()
});
}
else
{
formatedMessage = String.Format("{0} {1,-5} {2,-8} - {3}", new object[]{
DateTime.Now.ToString("MM-dd HH:mm:ss.fff"),
level.ToString(),
category,
exception.ToString()
});
}
try
{
int retryCount = 0;
while (true)
{
retryCount++;
try
{
string fileName = AppDomain.CurrentDomain.MapPhysicalPath("logs\\" + logFile);
if (!System.IO.Directory.Exists(System.IO.Path.GetDirectoryName(fileName)))
{
System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(fileName));
}
using (System.IO.FileStream fs = new System.IO.FileStream(
GetCurrentLogFile(fileName),
System.IO.FileMode.Append,
System.IO.FileAccess.Write, FileShare.Read)
)
{
using (System.IO.StreamWriter w = new System.IO.StreamWriter(fs, Encoding.Default))
{
w.WriteLine(formatedMessage);
}
}
break;
}
catch
{
if (retryCount >= 5)
{
throw;
}
System.Threading.Thread.Sleep(200);
}
}
}
catch (Exception err)
{
LogToUnhandledExceptions(
String.Format("{0}\r\n原始要写入的消息为:\r\n{1}", err.GetFriendlyToString(), message)
);
}
}
示例9: CreateSelectItem
private static SelectListItem CreateSelectItem(Level level)
{
var sel = new SelectListItem
{
Text = level.DisplayName,
Value = level.ToString()
};
return sel;
}