Показать сообщение отдельно
Старый 13.08.2009, 15:05   #1  
Blog bot is offline
Blog bot
Участник
 
25,646 / 848 (80) +++++++
Регистрация: 28.10.2006
CRM Programmer: How to write into the eventlog custom journal with impersonalization in code
Источник: http://crmpro.blogspot.com/2009/07/h...og-custom.html
==============


private const string LOG_NAME = "MSCRM.Common";

///
/// Write message in log
///
public static void WriteLog(string message, Exception exception)
{
System.Security.Principal.WindowsImpersonationContext ctx = null;
ctx = System.Security.Principal.WindowsIdentity.Impersonate(IntPtr.Zero);
try
{
string logSource = "MSCRM.Common.Web.Controls.Grid";

if (EventLog.SourceExists(logSource))
{
if (!EventLog.LogNameFromSourceName(logSource, ".").Equals(LOG_NAME))
{
EventLog.DeleteEventSource(logSource, ".");
EventLog.CreateEventSource(logSource, LOG_NAME);
}
}
else
{
EventLog.CreateEventSource(logSource, LOG_NAME);
}
EventLog el = new EventLog();
el.Log = LOG_NAME;
el.Source = logSource;
el.WriteEntry(String.Format("{0}\nDetails:\n{1}", message, GetLogInfo(exception)), EventLogEntryType.Error);
}
catch (Exception ex)
{
throw ex;
}
finally
{
ctx.Undo();
}
}



Источник: http://crmpro.blogspot.com/2009/07/h...og-custom.html
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.