none
Error in Expression Shape RRS feed

  • Question

  • Hi,

    I am trying to write a biztalk message to event log. 

    Please see the Expression in the Below image. Getting Error in ReceiveInfo Expression Shape. 

    Error : 

    xlang/s engine event log entry: Uncaught exception (see the 'inner exception' below) has suspended an instance of service 

    Thanks,

    Rajeshwari M.L 


    Tuesday, September 13, 2016 7:47 AM

Answers

  • STOP!  STOP!  Forget everything posted here so far...well maybe not every thing, but we have to star over.

    This is very simple.

    1. Pre-create* a custom Event Source for you app's internal errors.  You can use PowerShell to do this with the New-EventLog command.  See here: New-EventLog

    2. Write entries using your custom Source: System.Diagnostics.EventLog.WriteEntry("MyCustomSource", "Something Bad, or Good, happened!");

    *You must never, ever, use any code such as this in your app:

    System.Diagnostics.EventLog.CreateEventSource("MyCustomSource", "Application");

    CreateEventSource() required elevated permissions which a BizTalk Host Instance should never have.  This is not even OK for DEV.

    It's perfectly fine to use the Application Event Log, after all, you are creating an Application.  You Application though is it's own Source.


    • Edited by Johns-305MVP Tuesday, September 13, 2016 3:28 PM
    • Marked as answer by Rajeshwari ML Thursday, September 15, 2016 8:04 AM
    Tuesday, September 13, 2016 3:27 PM
  • Hi Rajeshwari,

    what you can do is create a new eventlog for your Instrumentation of Biztalk app..You can use the Powershell cmdlet New-Eventlog to create the event logand thenwrite to this particular eventlog ...

    This satisfies the condition that the custom events are not being written to the default application log.

    Also makesure that you are not adding the user of Host Instances to the admin group but rather the BizTalk Application users group should have rights to the Registry key that was mentioned above. (because host instance user should not have more rights than necessary)

    When I mentioned in abovepost that a powershell script can be used to move the events logged from certain source to new event log, you can achieve this using the method mentioned by Johns, that way it becomes easy tomaintain from start rather than running the Powershell script to move the log from the default application event log to a seperate one.

    Regards,


    Mandar Dharmadhikari

    • Marked as answer by Rajeshwari ML Thursday, September 15, 2016 8:05 AM
    Wednesday, September 14, 2016 7:57 AM
  • Hi Rajeshwari

    You can also use a PowerShell script to create the custom event source, as John suggested. This will be easier.

    You can add this script to your BizTalk application as a Post-processing Script. It is described here-

    https://msdn.microsoft.com/en-in/library/aa560803.aspx

    So, when you import/install this app in a new server, the script would get executed and the EventSource created for you. The user account that does this installation needs to be an Administrator on the box.

    An example of this approach is discussed here (see "Register an application source name in the registry, for logging to the Event Log" section) -

    http://geekswithblogs.net/EltonStoneman/archive/2009/06/08/using-powershell-in-biztalk-post-processing-scripts.aspx


    Thanks Arindam


    Wednesday, September 14, 2016 10:40 AM
    Moderator
  • You mean to say we should not create custom event source in biztalk application

    You should never try to create any Event Log entity (Log, Source, etc) inside your application because that required elevated permissions which your app should never have.

    You should always create custom Event Sources for you app. But, you must create them outside the app such as during Setup/Deployment with a script or part of the Installer.

    Wednesday, September 14, 2016 11:30 AM

All replies

  • Hi Rajeshwari

    So, the error means that there was no event source called "Message" in your event logs- this is the first parameter that you are passing in the call.

    Before writing to that event source ("Message"), create the source if it does not exist as below snippet. So code in the expression shape will be as follows-

    if (!System.Diagnostics.EventLog.SourceExists("Message"))
    {
       System.Diagnostics.EventLog.CreateEventSource("Message", "Application");
    }
    System.Diagnostics.EventLog.WriteEntry("Message", XMLDocument.OuterXml);

    Refer -

    https://sandroaspbiztalkblog.wordpress.com/2012/02/16/the-source-was-not-found-but-some-or-all-event-logs-could-not-be-searched-inaccessible-logs-security/

    After the code change as above, you also need to check for security permissions for the BizTalk Host Instance service account. Read on that below-

    CAUSE

    This problem occurs because the user account that you used to log on does not have sufficient permissions.
    The first time that you call the EventLog.CreateEventSource() method to create a custom event log, the custom event log entry is created under the following registry subkey:

    • HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog

    To create this subkey entry, you must have permission to write. However, the regular user account does not have permission to write.

    So, the user that runs the application must have administrative rights to create a new event log source or a new custom log.

    SOLUTION

    You need to grant permission to create a custom event log:

    • Log on to the computer as an administrator.
    • Click Start, click Run, type regedit in the Open box, and then click OK. The Registry Editor window appears.
    • Locate the following registry subkey:
      • HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog
    • Right-click Eventlog, and then click Permissions. The Permissions for Eventlog dialog box appears.

    eventviewer-permissions

    • Click Add, add the user account or group that you want and set the following permissions: “Full Control”

    eventviewer-permissions-options


    Thanks Arindam





    Tuesday, September 13, 2016 7:50 AM
    Moderator
  • Hi Rajeshwari

    Which user account did you provide registry access for? The BizTalk Host Instance service account?

    Also did you restart the Host Instance after deployment?


    Thanks Arindam

    Tuesday, September 13, 2016 8:49 AM
    Moderator
  • Hi Rajeshwari,

    Hold On!!

    Dont write to the event log.. writring to the default application log is not a good idea...it just over populates the event log with the custom logs...Windows application log is supposed to be used by biztalk, SQL and IIS to write some of their predifned errors, warnings and Informations..So writing to event log might seem andeasy choice oflogging from a developer perspective but is a nightmare for a Biztalk Admin, when some Biztalk debugging needs to be done.

    Instead of using the Event Log to write the custom logs,

    use the Event Trace to write the logs and then read them using debugTrace application.

    You can do something like

    System.Trace.WriteLine("This is a custom trace");

    to write to the trace and read it using DebugView.

    You can find it here(DebugView)

    Having said that,

    In this particular case make sure that the id configured on the Host Instance running this particular orchestration has rights to write to the event log.

    Regards,


    Mandar Dharmadhikari

    Tuesday, September 13, 2016 9:02 AM
  • Ok, make sure of-

    1) This orchestration is bound to the above Host Instance

    2) The orchestration assembly was re-deployed correctly

    3) The Host Instance was restarted.


    Thanks Arindam

    Tuesday, September 13, 2016 9:11 AM
    Moderator
  • Also just to add

    Makesure that the BizTalkApplicationUsers have the rights on the registry key mentioned in the above post...

    Regards,

    Mandar Dharmadhikari


    Mandar Dharmadhikari

    Tuesday, September 13, 2016 9:19 AM
  • Can you paste the code you have?

    Also just as a test, can you add the BizTalk Host Instance account to the Local Administrators group?

    Compmgmt.msc -> Local Users and Groups-> Groups -> Administrators - add it here.


    Thanks Arindam


    Tuesday, September 13, 2016 10:25 AM
    Moderator
  • Now that the event source is created, I would suggest you remove the BizTalk service account from the Administrators group.

    When you want to migrate this app to a new environment server, you can create s C# script that creates the above event source during app installation time. This script would be run using an Admin account.


    Thanks Arindam


    Tuesday, September 13, 2016 10:57 AM
    Moderator
  • Well Rajeshwari,

    Have you checked if the BizTalk Application Users group has the proper permissions on the Registry key??

    If they have I guess you will not need to add the user under host Instance to the administartors groups

    Regards,


    Mandar Dharmadhikari

    Tuesday, September 13, 2016 11:13 AM
  • As a Admin, I would discourage the practice...but even if there are custom logs in the event log, a powershell script can be written to move the custom logs to a different windows log.

    As a developer I would suggest to look at the Tracing option that I suggested...

    Regards,


    Mandar Dharmadhikari

    Tuesday, September 13, 2016 12:53 PM
  • Yes, the code is fine.

    To track historical errors/events in your app you can either use the event logs approach. Or a more sophisticated approach of logging all exceptions to a centralized location. One such example is the ESB Exception Handling framework. You can create a similar centralized pattern to handle all exceptions in your app, if time permits. 


    Thanks Arindam

    Tuesday, September 13, 2016 1:10 PM
    Moderator
  • Trace class will not persist any logs. Hence, they are only useful for debugging an issue when you can reproduce the issue at will, eg: in dev or a recurring error in prod. Not so much helpful when you cannot replay a message and produce the error. Therefore, you need a way to persist/store logs, especially error logs, so that you have sufficient information to troubleshoot the issue later.


    Thanks Arindam


    Tuesday, September 13, 2016 2:08 PM
    Moderator
  • Hi Rajeshwari,

    The traces will not be saved directly. It is used just for debugging purposes. In case you need to maintain the records for a longer period of time, I believe an event log will not help yunless you archive the older data using a powershell script.

    In case if you want to save the data (req resp messages), then I would suggest you to implement some archiving mechanism to store the messages to the Files or databases.

    I have used the CAT Logging Framework and Nlog framework to store the data to files.

    In case of tracking important data you can look at using BAM feature of biztalk.

    Then again, if you can provide the exact need..(i.e if you want the messsages to be available in future or just debug what stweps the orchestration isgoing through or just tracking some important business documents)

    in case you want tomove the logs you can havwe a look at following link

    https://technet.microsoft.com/en-us/magazine/8d7932f7-8d8d-4ee0-9510-45ece6b5f1ca?f=255&MSPPError=-2147217396

    http://liveaverage.com/features/coding/powershell-script-windows-event-log-retention-and-compression/

    Regards,


    Mandar Dharmadhikari


    Tuesday, September 13, 2016 2:12 PM
  • Yes, auto archival works nicely if your event logs get full. You can refer this thread.

    Thanks Arindam



    Tuesday, September 13, 2016 3:18 PM
    Moderator
  • STOP!  STOP!  Forget everything posted here so far...well maybe not every thing, but we have to star over.

    This is very simple.

    1. Pre-create* a custom Event Source for you app's internal errors.  You can use PowerShell to do this with the New-EventLog command.  See here: New-EventLog

    2. Write entries using your custom Source: System.Diagnostics.EventLog.WriteEntry("MyCustomSource", "Something Bad, or Good, happened!");

    *You must never, ever, use any code such as this in your app:

    System.Diagnostics.EventLog.CreateEventSource("MyCustomSource", "Application");

    CreateEventSource() required elevated permissions which a BizTalk Host Instance should never have.  This is not even OK for DEV.

    It's perfectly fine to use the Application Event Log, after all, you are creating an Application.  You Application though is it's own Source.


    • Edited by Johns-305MVP Tuesday, September 13, 2016 3:28 PM
    • Marked as answer by Rajeshwari ML Thursday, September 15, 2016 8:04 AM
    Tuesday, September 13, 2016 3:27 PM
  • Hi Rajeshwari,

    what you can do is create a new eventlog for your Instrumentation of Biztalk app..You can use the Powershell cmdlet New-Eventlog to create the event logand thenwrite to this particular eventlog ...

    This satisfies the condition that the custom events are not being written to the default application log.

    Also makesure that you are not adding the user of Host Instances to the admin group but rather the BizTalk Application users group should have rights to the Registry key that was mentioned above. (because host instance user should not have more rights than necessary)

    When I mentioned in abovepost that a powershell script can be used to move the events logged from certain source to new event log, you can achieve this using the method mentioned by Johns, that way it becomes easy tomaintain from start rather than running the Powershell script to move the log from the default application event log to a seperate one.

    Regards,


    Mandar Dharmadhikari

    • Marked as answer by Rajeshwari ML Thursday, September 15, 2016 8:05 AM
    Wednesday, September 14, 2016 7:57 AM
  • Hi Rajeshwari

    This ties in with what I mentioned yesterday-

    "Now that the event source is created, I would suggest you remove the BizTalk service account from the Administrators group.

    When you want to migrate this app to a new environment server, you can create s C# script that creates the above event source during app installation time. This script would be run using an Admin account."

    Basically, you should ensure that the Event Source exists prior to any BizTalk code that gets executed. Then you wouldn't even need the logic to create the EventSource from within BizTalk code. In your case, the event source is named "Message". I would suggest you change the name to the BizTalk application name, so that you know from where it is coming. Apart from these changes, you don't need to change anything else.


    Thanks Arindam

    Wednesday, September 14, 2016 8:04 AM
    Moderator
  • Hi Rajeshwari

    You can also use a PowerShell script to create the custom event source, as John suggested. This will be easier.

    You can add this script to your BizTalk application as a Post-processing Script. It is described here-

    https://msdn.microsoft.com/en-in/library/aa560803.aspx

    So, when you import/install this app in a new server, the script would get executed and the EventSource created for you. The user account that does this installation needs to be an Administrator on the box.

    An example of this approach is discussed here (see "Register an application source name in the registry, for logging to the Event Log" section) -

    http://geekswithblogs.net/EltonStoneman/archive/2009/06/08/using-powershell-in-biztalk-post-processing-scripts.aspx


    Thanks Arindam


    Wednesday, September 14, 2016 10:40 AM
    Moderator
  • Hi rajeshwari,

    before you import the appon a new environment, you can run the c# Script/Powershell script to create your own event log and then once the app is deplotyed, it will start writing to the new event log but you have to make sure that the Source is properly mentioned in the event log while writing to the event log.

    Regards,


    Mandar Dharmadhikari

    Wednesday, September 14, 2016 10:42 AM
  • You mean to say we should not create custom event source in biztalk application

    You should never try to create any Event Log entity (Log, Source, etc) inside your application because that required elevated permissions which your app should never have.

    You should always create custom Event Sources for you app. But, you must create them outside the app such as during Setup/Deployment with a script or part of the Installer.

    Wednesday, September 14, 2016 11:30 AM
  • Rajeshwari ML,

    This thread has gotten a bit out of control and includes a lot of simply incorrect information, including both Marked Answers.  For the benefit of future readers, you should unmark those.

    I would even recommend deleting this entire thread and start a new one.

    Wednesday, September 14, 2016 11:37 AM
  • That's correct, even point 2 is not needed. Provided at setup time, the custom Event source gets created. The setup/script to create the Event source needs to be run with a local Admin account.

    Thanks Arindam

    Thursday, September 15, 2016 10:09 AM
    Moderator
  • 1.Like below code. i should not create event source from the application. and this has to be done using script during setup/deployment time.

    System.Diagnostics.EventLog.CreateEventSource("MyCustomSource", "Application");

    2.not adding the user of Host Instances to the admin group but rather the BizTalk Application users group should have rights to the Registry key

    I think you're way over thinking this now.

    1. Correct, never do this.  That was bad advice, pretend you never say it.

    2. NO!  Again modifying any permissions was very bad advice, pretend you never saw it.

    All you need to remember is pre-create your Event Source at setup/deployment, you only have to do it once.  Use WriteEvent() in your app to create log Events with your custom source.


    • Edited by Johns-305MVP Thursday, September 15, 2016 11:37 AM
    Thursday, September 15, 2016 11:36 AM