To develop a cloud service program, if you use the local stroage to store our temporarily generated logs or files and upload them automatically to the Blob, you can do so through wad, as follows:
1. Configure Webrole to turn on the local stroage feature:
2. Modify the Wadcfgx file to add the DataSources attribute:
3. Add the code uploaded to the local storage:
Index.cshtml
@{Viewbag.title="Home Page";}<divclass="Jumbotron"> class=" Lead">asp.net isA free web framework forBuilding great Web sites and Web applicationsusingHTML, CSS and javascript.</p> <p><a href="http://asp.net" class="btn btn-primary Btn-lg">learn more »</a></p></div><divclass="Row"> <divclass="col-md-12">@using (Html.BeginForm ("Uploadzipfile","Home", FormMethod.Post,New{enctype ="Multipart/form-data" })) { <divclass="Form-group"> <label for="ZipFile">zip file</label> <input type="file"Id="ZipFile"Name="ZipFile"> </div> <button type="Submit" class="btn Btn-default">Submit</button> } </div></div>
The corresponding HomeController.cs implementations are as follows:
Publicactionresult uploadzipfile (httppostedfilebase zipfile) {varLocalresource = Roleenvironment.getlocalresource ("Zipfiles"); //Save zip file. varLocalzipfilepath =Path.Combine (Localresource.rootpath, zipfile.filename); Zipfile.saveas (Localzipfilepath); //Extract zip file to a random folder. varLocalextractedpath =Path.Combine (Localresource.rootpath, Guid.NewGuid (). ToString ()); Directory.CreateDirectory (Localextractedpath); System.IO.Compression.ZipFile.ExtractToDirectory (Localzipfilepath, Localextractedpath); //Upload everything to blob storage. foreach(varFileinchDirectory.GetFiles (Localextractedpath,"*", Searchoption.alldirectories)) { //Upload to blob storage. } returnRedirecttoaction ("Index"); }
The path to get the local Storege is: var localresource = Roleenvironment.getlocalresource ("Zipfiles");
3. I have done a local test, through the code upload to the settings of the local storage, through the RDP login instance, you will see the file already exists, the path is the c:\resources\directory\{deployment ID}. Webrole1.zipfiles
4. Once the designated local storage has the content, the corresponding storage account will generate the container Wad-testcustom (this is also the name of their own settings), the log automatically uploaded successfully, you will see the corresponding storage account container, upload the previously tested files:
For details, refer to: http://blogs.msdn.com/b/davidhardin/archive/2011/03/31/ Configuring-diagnostics-wadcfg-to-capture-custom-log-files.aspx
About the local Storage, even if not tick "clean on role Recycle", when the node failover, if some of the logs have not been stored in time to the BLOB, we will still lose them, specifically, you can refer to:
http://justazure.com/microsoft-azure-cloud-services-part-3-service-package/
Cloudservie automatically uploads content from localstroage to blobs via wad