本文整理汇总了C#中Microsoft.Practices.EnterpriseLibrary.Logging.LogEntry类的典型用法代码示例。如果您正苦于以下问题:C# LogEntry类的具体用法?C# LogEntry怎么用?C# LogEntry使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LogEntry类属于Microsoft.Practices.EnterpriseLibrary.Logging命名空间,在下文中一共展示了LogEntry类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProductInfo
public ProductInfo(string id)
{
_id = id;
DataFactory df = new DataFactory();
DataSet ds = new DataSet();
try
{
string sql = "select * from productinfo where productId=" + id;
ds = df.DataBind(sql);
}
catch (Exception ex)
{
LogEntry entry = new LogEntry();
entry.Severity = System.Diagnostics.TraceEventType.Error;
entry.Message = string.Format("Exception:{0}, Inner Exception:{1}", ex.Message, ex.InnerException.Message);
entry.Categories.Add(Category.Exception);
entry.Priority = Priority.High;
logwrite.Write(entry);
throw;
}
DataRow row = ds.Tables[0].Rows[0];
_name = row["productName"].ToString().Trim();
_mainInfo =NoHTML(row["maininfo"].ToString().Trim());
_picURL = HttpContext.Current.Request.Url.Host.ToString().TrimEnd('/') +"/productPic/" + row["pic"].ToString().Trim();
_pdfURL =string.IsNullOrEmpty(row["pdf"].ToString().Trim())==true? "" : HttpContext.Current.Request.Url.Host.ToString().TrimEnd('/')+ "/productPdf/" + row["pdf"].ToString().Trim();
_price = row["price"].ToString().Trim() == "0" ? "" : row["price"].ToString().Trim();
_isNew = row["isNew"].ToString().Trim();
_isPromotion = row["isPromotion"].ToString().Trim();
}
示例2: RedirectsToCommonLogging
public void RedirectsToCommonLogging()
{
CapturingLoggerFactoryAdapter testLoggerFactoryAdapter = new CapturingLoggerFactoryAdapter();
LogManager.Adapter = testLoggerFactoryAdapter;
// force entlib logging init
Logger.Write("init");
// ensure external configuration didn't change
Assert.AreEqual("Test Capturing Listener", TestCommonLoggingEntlibTraceListener.Instance.Name);
LogEntry logEntry = new LogEntry();
logEntry.Categories.Add("mycategory");
logEntry.Message = "testmessage";
ILogFormatter formatter = TestCommonLoggingEntlibTraceListener.Instance.Formatter;
string s = formatter.Format(logEntry);
Assert.AreEqual("Category: mycategory, Message: testmessage", s);
using (TestCommonLoggingEntlibTraceListener.Instance.Capture())
{
// note that output depends on the formatter configured for the entlib listener!
Logger.Write("message1");
Assert.AreEqual("Category: General, Message: message1", testLoggerFactoryAdapter.LastEvent.RenderedMessage);
Assert.AreEqual(LogLevel.Info, testLoggerFactoryAdapter.LastEvent.Level);
Logger.Write("message2", "custom category", -1, -1, TraceEventType.Warning);
Assert.AreEqual("Category: custom category, Message: message2", testLoggerFactoryAdapter.LastEvent.RenderedMessage);
Assert.AreEqual("Test Capturing Listener/All Events", testLoggerFactoryAdapter.LastEvent.Source.Name);
Assert.AreEqual(LogLevel.Warn, testLoggerFactoryAdapter.LastEvent.Level);
}
}
示例3: RedirectsToCommonLogging
public void RedirectsToCommonLogging()
{
CapturingLoggerFactoryAdapter testLoggerFactoryAdapter = new CapturingLoggerFactoryAdapter();
LogManager.Adapter = testLoggerFactoryAdapter;
// force entlib logging init
Logger.SetLogWriter(new LogWriterFactory().Create());
Logger.Write("init");
// ensure external configuration didn't change
LogEntry logEntry = new LogEntry();
logEntry.Categories.Add("mycategory");
logEntry.Message = "testmessage";
// Change to EL 6 (no longer uses Unity) so need to get listener via LogWriter
var allEventsSource = Logger.Writer.GetMatchingTraceSources(logEntry).First(source => "All Events".Equals(source.Name));
var listener = (CommonLoggingEntlibTraceListener) allEventsSource.Listeners.First(l => l is CommonLoggingEntlibTraceListener);
Assert.IsTrue(listener.Name.StartsWith("Test Capturing Listener"));
ILogFormatter formatter = listener.Formatter;
string s = formatter.Format(logEntry);
Assert.AreEqual("Category: mycategory, Message: testmessage", s);
// note that output depends on the formatter configured for the entlib listener!
Logger.Write("message1");
Assert.AreEqual("Category: General, Message: message1", testLoggerFactoryAdapter.LastEvent.RenderedMessage);
Assert.AreEqual(LogLevel.Info, testLoggerFactoryAdapter.LastEvent.Level);
Logger.Write("message2", "custom category", -1, -1, TraceEventType.Warning);
Assert.AreEqual("Category: custom category, Message: message2", testLoggerFactoryAdapter.LastEvent.RenderedMessage);
Assert.AreEqual("Test Capturing Listener/All Events", testLoggerFactoryAdapter.LastEvent.Source.Name);
Assert.AreEqual(LogLevel.Warn, testLoggerFactoryAdapter.LastEvent.Level);
}
示例4: CreateInstance
/// <summary>
/// Creates a preconfigured instance of a LogEntry.
/// </summary>
/// <param name="severity">Severity of the log entry.</param>
/// <param name="message">Error message</param>
/// <param name="title">Title of the log entry</param>
/// <param name="includeSecurityDetail">if set to <c>true</c> security information is included in the log.</param>
/// <returns>Configured LogEntry instance</returns>
public LogEntry CreateInstance(
TraceEventType severity, string message, string title, bool includeSecurityDetail)
{
LogEntry le = new LogEntry();
if (string.IsNullOrEmpty(title))
{
le.Title = "Untitled";
}
else
{
le.Title = title;
}
le.Message = message;
le.Severity = severity;
Dictionary<string, object> dictionary = new Dictionary<string, object>();
if (includeSecurityDetail)
{
ManagedSecurityContextInformationProvider informationHelper = new ManagedSecurityContextInformationProvider();
informationHelper.PopulateDictionary(dictionary);
UnmanagedSecurityContextInformationProvider unmanagedHelper = new UnmanagedSecurityContextInformationProvider();
unmanagedHelper.PopulateDictionary(dictionary);
}
le.ExtendedProperties = dictionary;
return le;
}
示例5: GetCategories
public CampaignSetupModel GetCategories(CampaignSetupModel model)
{
var scw = new ServiceClientWrapper();
// create AdCopy array
// get categories or classifications
var categories = scw.GetCategories(null, model.ProductGroup.ProductPromotionName,
model.ProductGroup.Words,
model.AdModelProp.Ads.Select(
pad => pad.AdTitle + " " + pad.AdTextLine1 + " " + pad.AdTextLine2).
ToArray(), model.AdModelProp.LandingUrl);
// create categories list that will be displayed in a multiselect list box
if (categories != null && categories.Count > 0)
{
for (var i = 0; i < categories.Count; i++)
{
var cm = new CampaignSetupModel.CategoriesModel {Id = i, Name = categories[i]};
model.AllCategories.Add(cm);
}
}
else
{
var logEnty = new LogEntry
{ActivityId = Guid.NewGuid(), Message = "Could not get Categories from web service"};
Logger.Write(logEnty);
}
return model;
// save this some how while getting the keywords this is becoming null
}
示例6: LogError
public void LogError(string message)
{
LogEntry entry = new LogEntry();
entry.Message = message;
entry.Categories.Add("Error");
Logger.Write(entry);
}
示例7: ShouldCacheTheMessagesBasedOnCacheInterval
public void ShouldCacheTheMessagesBasedOnCacheInterval()
{
var listener = new CachedEmailTraceListener(
string.Empty,
string.Empty,
string.Empty,
string.Empty,
string.Empty,
2500,
null,
EmailAuthenticationMode.WindowsCredentials,
string.Empty,
string.Empty,
false,
1.0); // 1 hour cache time
var logEntry = new LogEntry { Message = "ABC Error", Severity = TraceEventType.Error};
try
{
listener.TraceData(null, string.Empty, TraceEventType.Error, 1, logEntry);
// If no exception
Assert.Fail();
}
catch (ArgumentException ex)
{
Assert.AreEqual("The parameter 'address' cannot be an empty string.\r\nParameter name: address", ex.Message);
}
catch
{
Assert.Fail();
}
//Second call should not hit the base TraceData call..
listener.TraceData(null, string.Empty, TraceEventType.Error, 1, logEntry);
}
示例8: RedirectsToCommonLogging
public void RedirectsToCommonLogging()
{
CapturingLoggerFactoryAdapter testLoggerFactoryAdapter = new CapturingLoggerFactoryAdapter();
LogManager.Adapter = testLoggerFactoryAdapter;
// force entlib logging init
Logger.Write("init");
var listener =(CommonLoggingEntlibTraceListener) ((TraceListenerWrapper)EnterpriseLibraryContainer.Current.GetInstance<TraceListener>("Test Capturing Listener")).InnerTraceListener;
// ensure external configuration didn't change
// change to starts with because entlib now wraps all listeners and changes the name
Assert.IsTrue(listener.Name.StartsWith("Test Capturing Listener"));
LogEntry logEntry = new LogEntry();
logEntry.Categories.Add("mycategory");
logEntry.Message = "testmessage";
ILogFormatter formatter = listener.Formatter;
string s = formatter.Format(logEntry);
Assert.AreEqual("Category: mycategory, Message: testmessage", s);
// note that output depends on the formatter configured for the entlib listener!
Logger.Write("message1");
Assert.AreEqual("Category: General, Message: message1", testLoggerFactoryAdapter.LastEvent.RenderedMessage);
Assert.AreEqual(LogLevel.Info, testLoggerFactoryAdapter.LastEvent.Level);
Logger.Write("message2", "custom category", -1, -1, TraceEventType.Warning);
Assert.AreEqual("Category: custom category, Message: message2", testLoggerFactoryAdapter.LastEvent.RenderedMessage);
Assert.AreEqual("Test Capturing Listener/All Events", testLoggerFactoryAdapter.LastEvent.Source.Name);
Assert.AreEqual(LogLevel.Warn, testLoggerFactoryAdapter.LastEvent.Level);
}
示例9: WriteActivity
public static void WriteActivity(string functionName, string message)
{
var logEntry = new LogEntry();
logEntry.Message = message;
Logger.Write(logEntry);
}
示例10: LogException
/// <summary>
/// Logs the exception - Critical Level.
/// </summary>
/// <param name="exception">The exception.</param>
public void LogException(Exception exception)
{
LogEntry logEntry = new LogEntry();
logEntry.Message = string.Format(logTemplate, exception.Message, exception.StackTrace);
logEntry.Severity = TraceEventType.Critical;
Microsoft.Practices.EnterpriseLibrary.Logging.Logger.Write(logEntry);
}
示例11: LogEntry
public static void LogEntry(string message)
{
LogEntry log = new LogEntry();
log.Message = message;
MessageBox.Show(message);
//Logger.Write(log);
}
示例12: LogToDatabase
static void LogToDatabase()
{
// Check if logging is enabled before creating log entries.
if (defaultWriter.IsLoggingEnabled())
{
// Create a Dictionary of extended properties
Dictionary<string, object> exProperties = new Dictionary<string, object>();
exProperties.Add("Extra Information", "Some Special Value");
// Create a LogEntry using the constructor parameters.
defaultWriter.Write("Log entry with category, priority, event ID, severity, title, and extended properties.", "Database",
5, 9008, TraceEventType.Warning, "Logging Block Examples", exProperties);
Console.WriteLine("Created a log entry with a category, priority, event ID, severity, title, and extended properties.");
Console.WriteLine();
// Create a LogEntry using the constructor parameters.
LogEntry entry = new LogEntry("LogEntry with category, priority, event ID, severity, title, and extended properties.", "Database",
8, 9009, TraceEventType.Error, "Logging Block Examples", exProperties);
defaultWriter.Write(entry);
Console.WriteLine("Created and written LogEntry with a category, priority, event ID, severity, title, and extended properties.");
Console.WriteLine();
Console.WriteLine(@"Open the 'Logging.mdf' database in the Bin\Debug folder to see the results.");
}
else
{
Console.WriteLine("Logging is disabled in the configuration.");
}
}
示例13: AddNewItemToTraceList
public void AddNewItemToTraceList(TraceEventType eventType, string message)
{
LogEntry leNewTraceItem = new LogEntry();
leNewTraceItem.Message = message;
leNewTraceItem.Severity = eventType;
leNewTraceItem.TimeStamp = DateTime.Now;
lock (lockObject)
{
lstFreshTrace.Add(leNewTraceItem);
if ( eventType == TraceEventType.Critical || eventType == TraceEventType.Error || eventType == TraceEventType.Warning )
{
lstFreshTraceErrors.Add(leNewTraceItem);
}
if ( lstFreshTraceErrors.Count > errorsNumber )
{
lstFreshTraceErrors.RemoveAt(0);
}
if (lstFreshTrace.Count > infoNumber)
{
lstFreshTrace.RemoveAt(0);
}
}
}
示例14: WriteLog
public static void WriteLog(string message, string category, string status, System.Diagnostics.TraceEventType eventType, string name, string filename, int priority)
{
//DatabaseFactory.SetDatabaseProviderFactory(new DatabaseProviderFactory());
//DatabaseProviderFactory factory = new DatabaseProviderFactory();
//Database db = factory.Create("Logging");
//DatabaseFactory.SetDatabaseProviderFactory(factory, true);
DatabaseProviderFactory factory = new DatabaseProviderFactory(new SystemConfigurationSource(false).GetSection);
DatabaseFactory.SetDatabaseProviderFactory(factory, false);
LogWriterFactory logWriterFactory = new LogWriterFactory();
Logger.SetLogWriter(logWriterFactory.Create());
LogEntry log = new LogEntry();
log.Categories.Add(category);
log.Message = status + " : " + message;
log.EventId = 1;
log.Priority = priority;
if (!string.IsNullOrEmpty(name.Trim()))
log.ManagedThreadName = name;
log.TimeStamp = System.DateTime.Now;
log.Severity = eventType;
if (!string.IsNullOrEmpty(filename.Trim()))
log.Title = category + " : " + filename + " : " + message;
else
log.Title = category + " : " + message;
Logger.Write(log);
Logger.Reset();
}
示例15: ProcessContextItems
/// <summary>
/// Merges each key/value pair from the context items dictionary with the ExtendedProperties
/// dictionary of the <see cref="LogEntry"/>.
/// </summary>
/// <param name="log"><see cref="LogEntry"/> object that is being logged.</param>
public void ProcessContextItems(LogEntry log)
{
Hashtable contextItems = null;
// avoid retrieval if necessary permissions are not granted to the executing assembly
if (SecurityManager.IsGranted(new SecurityPermission(SecurityPermissionFlag.Infrastructure)))
{
try
{
contextItems = GetContextItems();
}
catch (SecurityException)
{
// ignore the security exception - no item could have been set if we get the exception here.
}
}
if (contextItems == null || contextItems.Count == 0)
{
return;
}
foreach (DictionaryEntry entry in contextItems)
{
string itemValue = GetContextItemValue(entry.Value);
log.ExtendedProperties.Add(entry.Key.ToString(), itemValue);
}
}