Writing a TXT or log File - UnauthorizedAccessException

Good Morning all !,
I’m getting an Error when I’m trying to write a plain TXT - log file. For some reason the BPM keeps displaying this error:
BPM runtime caught an unexpected exception of ‘UnauthorizedAccessException’ .

This was working fine before we moved the application to the cloud and clients are deployed locally.

Does anyone has a clue what’s going on. I’ve even tried to write to my C: drive and I get the same error:

BPM runtime caught an unexpected exception of ‘UnauthorizedAccessException’ type.
See more info in the Inner Exception section of Exception Details.

Exception caught in: Epicor.ServiceModel

Error Detail

Correlation ID: aaf8c553-d65e-46ea-8242-98d47c4ba64f
Description: BPM runtime caught an unexpected exception of ‘UnauthorizedAccessException’ type.
See more info in the Inner Exception section of Exception Details.
Program: CommonLanguageRuntimeLibrary
Method: WinIOError
Original Exception Type: UnauthorizedAccessException
Framework Method: A001_CustomCodeAction
Framework Line Number: 0
Framework Column Number: 0
Framework Source: A001_CustomCodeAction at offset 263 in file:line:column :0:0

Client Stack Trace

at Epicor.ServiceModel.Channels.ImplBase`1.ShouldRethrowNonRetryableException(Exception ex, DataSet[] dataSets)
at Erp.Proxy.BO.CustShipImpl.UpdateMaster(CustShipDataSet ds, Boolean doValidateCreditHold, Boolean doCheckShipDtl, Boolean doLotValidation, Boolean doCheckOrderComplete, Boolean doPostUpdate, Boolean doCheckCompliance, Boolean ipShippedFlagChanged, Int32 ipPackNum, Int32 ipBTCustNum, String& opReleaseMessage, String& opCompleteMessage, String& opShippingMessage, String& opLotMessage, String& opInventoryMessage, String& opLockQtyMessage, String& opAllocationMessage, String& opPartListNeedsAttr, String& opLotListNeedsAttr, String& shipCreditMsg, Boolean& cError, Boolean& compError, String& msg, String& opPostUpdMessage, Boolean& updateComplete, Boolean& checkComplianceError, Boolean& changeStatusError, Boolean& checkShipDtlAgain)
at Erp.Adapters.CustShipAdapter.UpdateMaster(Boolean doValidateCreditHold, Boolean doCheckShipDtl, Boolean doLotValidation, Boolean doCheckOrderComplete, Boolean doPostUpdate, Boolean doCheckCompliance, Boolean ipShippedFlagChanged, Int32 ipPackNum, Int32 ipBTCustNum, String& opReleaseMessage, String& opCompleteMessage, String& opShippingMessage, String& opLotMessage, String& opInventoryMessage, String& opLockQtyMessage, String& opAllocationMessage, String& opPartListNeedsAttr, String& opLotListNeedsAttr, String& shipCreditMsg, Boolean& cError, Boolean& compError, String& msg, String& opPostUpdMessage, Boolean& updateComplete, Boolean& checkComplianceError, Boolean& changeStatusError, Boolean& checkShipDtlAgain)
at Erp.UI.App.CustShipEntry.Transaction.Update()

Inner Exception

Access to the path ‘C:\ERROR_MAOLIN_2020_06_17_080119.txt’ is denied.

BPMs run server side - you are trying to write to your cloud providers server C:, which for obvious security reasons will be blocked.

2 Likes

Markdamem,
That’s an excellent point. Then how can I change the code to write a text file if the app is the cloud now ?. How does other people write logs if the app is now in the Cloud.

I’ll defer to our resident cloud expert @Mark_Wonsil on that one.

What is the purpose of this text file? Debugging?

Mark,
Yes, Write a text file when an error occurs in the code or even to see what people do in the app. Writing a Text file would be very helpful

Yes, logging is helpful but text files are now considered “old school”, especially in the cloud.

The easiest thing you can do right away is to log to a UD table then use a dashboard to view the logging. This is similar to Epicor’s ChgLog.

What the cool kids are doing is called “Structured Logging”. This is where you are logging Json data to a remote server. These repositories can then notify you about errors. Programs like Serilog, Log4net, Nlog, among others do this. I’ve seen evidence that Epicor is adding some logging but they need to really expand this to also log to a cloud service instead of the flat files on the server.

Within Azure, they offer a monitoring solution that works with structured logs. 5GB of logging is less than $3/month.

1 Like

if it is not cloud, Epicor server log can be used

First Option

Ice.Diagnostics.Log.WriteEntry("YourMsg");

It shows up in Epicors ServerLog.txt along with all the other logging such as BPM Execution etc. You can then access it via UNC Path if you have access or just the Web URL

http://MyServer/EpicorERP/ServerLog.txt

Second Option

Third Option
You can get the ServerLog Path (EpicorData) and it will allow you to write there. I need to find the helper Method but something like

Ice.Lib.FileName.ServerFileType.ServerLog
// You include Ice.Lib.Shared.dll as a reference in your BPM

string fullFilePath = Ice.Lib.FileName.Get("YourFileName", Ice.Lib.FileName.ServerFileType.Log);

Possible Options are:

    public enum ServerFileType
    {
        Log = 1,
        Temp = 2,
        Report = 3,
        Process = 4,
        ServerLog = 5,
        ServerTemp = 6,
        Custom = 7,
        UserData = 8
    }

Extra:
Im a big fan of writeFileLib because if multiple users are running the same BPM, you wont get file in use exceptions etc…

Ice.Lib.writeFileLib.FileWriteLine("YourPath/FileName.txt", ".......");

So Maybe something like

string fullFilePath = Ice.Lib.FileName.Get("Testing.txt", Ice.Lib.FileName.ServerFileType.Log);
Ice.Lib.writeFileLib.FileWriteLine(fullFilePath , "...hello....");

Lastly,
There is also PathHelper (I think this is Client side if i recall)

PathHelper.GetFolderPath(SpecialFolder.Attachment);

Possible Options:

public enum SpecialFolder
{
    Report,
    WebDeployment,
    ReportDefinition,
    CustomReportDefinition,
    UserData,
    CompanyData,
    EWADeployment,
    Attachment
}
3 Likes

Someday I’m going drag you young whippersnappers into modern computing… Now…

getoffmywan !

It is cloud Olga. That’s what started my DevOps rant. :wink:

I wonder if its his own Cloud, he can do Custom Code

Hello,
I’m new to Epicor and I’m trying to use your examples to write out messages to a log file.
We are using Epicor Kinetic in the cloud.
I can’t make sense of the line below. It gives me an error and I can’t see an alternative parm.
string fullFilePath = Ice.Lib.FileName.Get(“Testing.txt”, Ice.Lib.FileName.ServerFileType.Log);

thanks,
Mike