0
我有一个web应用程序有2个实例作为默认值,并从资源管理器,我可以看到有两个实例。 然而,在Global.asax中的代码,我有这样的代码:蔚蓝的web应用程序多个实例混淆
public class LogEntity : TableEntity
{
public LogEntity(string partitionKey, string rowKey)
{
this.PartitionKey = partitionKey;
this.RowKey = rowKey;
}
public LogEntity() { }
public string Submitter { get; set; }
}
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
Random ran = new Random();
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["StorageConnectionString"]);
var tableClient = storageAccount.CreateCloudTableClient();
CloudTable table = tableClient.GetTableReference("logs");
table.CreateIfNotExists();
var key1 = ran.Next();
var machineName1 = Environment.GetEnvironmentVariable("WEBSITE_INSTANCE_ID");
LogEntity log1 = new LogEntity(Environment.MachineName + ":" + machineName1 + ":" + key1.ToString(), "instance started");
TableBatchOperation batchOperation1 = new TableBatchOperation();
batchOperation1.Insert(log1);
table.ExecuteBatch(batchOperation1);
}
}
但是,从我的Azure Table中的日志,我只能看到一个生成的日志条目,它总是从同一个实例。
这是否意味着当我有多个实例时,只有一个实例会调用application_start?我认为所有实例都应该在独立运行时启动application_start。但是,我的日志似乎与我的理解矛盾。
UPDATE
我发现,记录到Azure Table中的代码。我期待的是,由于有两个实例,我应该看到在天蓝色表中创建的两个日志条目。但是,总是只有一个条目。
您可以分享您在执行应用程序启动时执行的代码吗?请用代码更新您的问题。 –
谢谢!什么是你试图插入的实体的PartitionKey/RowKey?我没有看到你的代码。如果你也可以包含'LogEntity'的代码,它也会有所帮助。 –
的partitionKey键包含实例ID和机器名,所以应该给我不同的条目针对不同的情况下 – daxu