RunWithElevatedPrivileges似乎隐藏了我的日志记录

时间:2011-04-26 17:28:57

标签: sharepoint nlog

嘿所有,我在IIS 7服务器上运行类,安装了所有Sharepoint yimmer yammer。我有使用MSDN网站上的演练创建的webservice。

我发现我需要使用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 个答案:

答案 0 :(得分:0)

提升的priveleges委托在其中运行代码作为Web应用程序帐户(即代码不再模仿运行代码的用户)。

找出运行Web应用程序的帐户,然后找出日志消息随用户更改的原因。