RunWithElevatedPrivileges似乎隐藏了我的日志记录
||
嘿,我正在IIS 7服务器上运行所有安装了Sharepoint yimmer yammer的类。我具有使用MSDN站点上的演练创建的Web服务。
我发现我需要使用ElevatedPrivilleges调用才能使我的LINQ类正常工作。
一旦执行完此操作,这似乎导致我的基于NLog的记录器无法找到与NLog档案所说的web.config文件位于同一目录的web.nlog文件。
委托之外的任何日志语句都可以正常工作,其中的任何内容都不会出现在日志文件中。
究竟是什么,那个代表中到底发生了什么?
using System;
using System.Web.Services;
using Notification.DAL;
using SharePointConnector;
using NLog;
using Microsoft.SharePoint;
namespace NotificationReceiverService
{
[WebService(Namespace = \"http://midwestiso.org/\")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class Service : System.Web.Services.WebService
{
private static Logger logger = LogManager.GetCurrentClassLogger();
private static readonly String MACHINE_NAME = Environment.MachineName.ToUpper();
public Service()
{
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public string HelloWorld()
{
return \"Hello World, You\'ve contacted the Notifications Receiver Service. \" +
\"Please refer to the WSDL for the other available methods\";
}
[WebMethod]
public string EchoMessage(string MESSAGE_TEMPLATE_NAME, string MESSAGE_SUBJECT, string MESSAGE_TEXT_SUMMARY,
string MESSAGE_TEXT_DETAIL, string MESSAGE_TEXT_CON_OPS)
{
return String.Format(\"You called EchoMessage and told me {0}, {1}, {2}, {3}, {4}\",
MESSAGE_TEMPLATE_NAME, MESSAGE_SUBJECT, MESSAGE_TEXT_SUMMARY, MESSAGE_TEXT_DETAIL, MESSAGE_TEXT_CON_OPS);
}
[WebMethod]
public string SendMessage(string MESSAGE_TEMPLATE_NAME, string MESSAGE_SUBJECT, string MESSAGE_TEXT_SUMMARY,
string MESSAGE_TEXT_DETAIL, string MESSAGE_TEXT_CON_OPS)
{
logger.Info(\"------\" + System.Reflection.Assembly.GetExecutingAssembly().GetName().Name + \" starting on \" + MACHINE_NAME + \"------\");
try
{
//SPSecurity.RunWithElevatedPrivileges(delegate
// {
int? newNotificationId = 0;
using (var db = new MISO_IR_IntegrationDataContext())
{
logger.Error(\"Message Received is: {0} - {1} - {2} - {3} - {4} - {5}\",
DateTime.UtcNow.AddHours(-5), MESSAGE_TEMPLATE_NAME.Trim(),
MESSAGE_SUBJECT.Trim(), MESSAGE_TEXT_SUMMARY.Trim(),
MESSAGE_TEXT_DETAIL.Trim(), MESSAGE_TEXT_CON_OPS.Trim());
int dbProcReturnCode = db.InsertReceivedNotification(DateTime.UtcNow.AddHours(-5),
MESSAGE_TEMPLATE_NAME.Trim(), MESSAGE_SUBJECT.Trim(), MESSAGE_TEXT_SUMMARY.Trim(),
MESSAGE_TEXT_DETAIL.Trim(), MESSAGE_TEXT_CON_OPS.Trim(), ref newNotificationId);
if (dbProcReturnCode == 0)
{
logger.Info(\"Notification saved to DB with ID: {0}\", newNotificationId);
logger.Debug(\"Getting read to call CreatePublishingPagefromNotification\");
// PagePublisher.CreatePublishingPagefromNotification((int)newNotificationId);
logger.Debug(\"Complete calling CreatePublishingPagefromNotification without exception\");
}
else
{
throw new Exception(\"Unable to find mapping for this MESSAGE_TEMPLATE, saved the message to the notification table with ERRORNOMAPPING code, aborting further processing\");
}
}
// });
}
catch (Exception ex)
{
logger.ErrorException(ex.Message, ex);
return \"ERRORPOOP\";
}
finally
{
logger.Info(\"------\" + System.Reflection.Assembly.GetExecutingAssembly().GetName().Name + \" COMPLETED ------\");
}
return \"OK\";
}
}
}
没有找到相关结果
已邀请:
1 个回复
磐去裸猜饲