本文整理汇总了C#中Microsoft.Practices.EnterpriseLibrary.Logging.LogEntry类的典型用法代码示例。如果您正苦于以下问题:C# LogEntry类的具体用法?C# LogEntry怎么用?C# LogEntry使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LogEntry类属于Microsoft.Practices.EnterpriseLibrary.Logging命名空间,在下文中一共展示了LogEntry类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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();
}
开发者ID:billmoling,项目名称:GardenWeb,代码行数:30,代码来源:ProductInfo.cs
示例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);
}
}
开发者ID:Rocketmakers,项目名称:common-logging,代码行数:30,代码来源:CommonLoggingEntlibTraceListenerTests.cs
示例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);
}
开发者ID:SchalkVersteeg,项目名称:common-logging,代码行数:33,代码来源:CommonLoggingEntlibTraceListenerTests.cs
示例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;
}
开发者ID:BogamSushil,项目名称:OnlineGrocery,代码行数:40,代码来源:LogEntryFactory.cs
示例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
}
开发者ID:rajskumar,项目名称:semplest2,代码行数:31,代码来源:CampaignRepository.cs
示例6: LogError
public void LogError(string message)
{
LogEntry entry = new LogEntry();
entry.Message = message;
entry.Categories.Add("Error");
Logger.Write(entry);
}
开发者ID:xxjeng,项目名称:nuxleus,代码行数:7,代码来源:ELLogger.cs
示例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);
}
开发者ID:kevinwiegand,项目名称:EnergyTrading-Core,代码行数:35,代码来源:CachedEmailTraceListenerFixture.cs
示例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);
}
开发者ID:abombss,项目名称:common-logging,代码行数:30,代码来源:CommonLoggingEntlibTraceListenerTests.cs
示例9: WriteActivity
public static void WriteActivity(string functionName, string message)
{
var logEntry = new LogEntry();
logEntry.Message = message;
Logger.Write(logEntry);
}
开发者ID:prasaddsr,项目名称:PrasadSample,代码行数:7,代码来源:Logger.cs
示例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);
}
开发者ID:sharmeran,项目名称:ATSWeb,代码行数:11,代码来源:LoggingUtil.cs
示例11: LogEntry
public static void LogEntry(string message)
{
LogEntry log = new LogEntry();
log.Message = message;
MessageBox.Show(message);
//Logger.Write(log);
}
开发者ID:tiemptit,项目名称:travelh2v,代码行数:7,代码来源:SystemHelper.cs
示例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.");
}
}
开发者ID:vvalotto,项目名称:PlataformaNET,代码行数:26,代码来源:Program.cs
示例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);
}
}
}
开发者ID:asimay,项目名称:LMS511Laser,代码行数:26,代码来源:TraceContentProvider.cs
示例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();
}
开发者ID:narayantalakanti,项目名称:PikeStormService,代码行数:33,代码来源:PikeStormLog.cs
示例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);
}
}
开发者ID:wuyingyou,项目名称:uniframework,代码行数:33,代码来源:ContextItems.cs
示例16: DnaWebProtocolException
/// <summary>
/// Throws a new WebProtocalException. Debug builds throw the exception along with the description and inner exception, release builds
/// only throw the StatusCode.
/// </summary>
/// <param name="StatusCode">The status code you want the exception to contain</param>
/// <param name="statusDescription">The description of the exception</param>
/// <param name="innerException">The origninal exception you caught if any</param>
public DnaWebProtocolException(HttpStatusCode statusCode, string statusDescription, Exception innerException)
{
StatusCode = statusCode;
StatusDescription = statusDescription;
if (String.IsNullOrEmpty(statusDescription))
{
if(innerException != null)
{
statusDescription = innerException.Message;
}
else
{
statusDescription = "";
}
}
LogEntry entry = new LogEntry()
{
Message = String.Format("{0}-{1}", StatusCode, statusDescription),
Severity = System.Diagnostics.TraceEventType.Error,
};
Logger.Write(entry);
this.detailWriter = new StringDetailWriter() { Detail = statusDescription, StatusCode = StatusCode, innerException = innerException, ErrorCode = ErrorType.Unknown.ToString() };
}
开发者ID:rocketeerbkw,项目名称:DNA,代码行数:37,代码来源:DnaWebProtocalException.cs
示例17: Create
public LogEntry Create(TraceEventType severity, IFormatProvider provider, string format, params object[] args) {
var entry = new LogEntry();
entry.Title = loggerName;
entry.Severity = severity;
entry.Message = string.Format(provider, format, args);
return entry;
}
开发者ID:aelveborn,项目名称:njupiter,代码行数:7,代码来源:LogEntryFactory.cs
示例18: lock
void IDnaLogger.Write(LogEntry log)
{
lock (_locker)
{
Microsoft.Practices.EnterpriseLibrary.Logging.Logger.Write(log);
}
}
开发者ID:rocketeerbkw,项目名称:DNA,代码行数:7,代码来源:DnaLogger.cs
示例19: WriteException
public static void WriteException(TraceEventType Severity, String ErrorMessage, String MethodName)
{
LogEntry entry = new LogEntry();
entry.Severity = Severity;
entry.Message = ErrorMessage;
Logger.Write(entry);
}
开发者ID:Yelena11,项目名称:Refactored_App,代码行数:7,代码来源:Error.cs
示例20: LogMessageAsync
private static void LogMessageAsync(LogEntry log)
{
using (TransactionScope transScope = new TransactionScope(TransactionScopeOption.Suppress))
{
Logger.Write(log);
}
}
开发者ID:jordivila,项目名称:Net_MVC_NLayer_Result,代码行数:7,代码来源:LoggingHelper.cs
注:本文中的Microsoft.Practices.EnterpriseLibrary.Logging.LogEntry类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论