I'm following the setup instructions for Setting up StackDriver Trace for C# ASP.NET. In the section "Configuring the client library", step 3:
In the Global.asax.cs file's WebApiApplication class add teh following Init code block to initialize trace:
public override void Init()
{
string projectId = ConfigurationManager.AppSettings["projectId"];
// ...
base.Init();
TraceConfiguration traceConfig = TraceConfiguration
.Create(bufferOptions: BufferOptions.NoBuffer());
CloudTrace.Initialize(this, projectId, traceConfig);
}
The TraceConfiguration object doesn't exist in either of the client libraries referenced in step 2:
using Google.Cloud.Diagnostics.AspNet;
using Google.Cloud.Diagnostics.Common;
I can't find any reference to this object, and doesn't appear to be built-in to the .net framework.
Assuming you're using this:
https://cloud.google.com/trace/docs/setup/aspnet
If I'm following this correctly, I think the documentation is out-of-date and TraceConfiguration was replaced with TraceOptions some time ago:
https://github.com/googleapis/google-cloud-dotnet/pull/1120
And:
TraceOptions
I'll ping the folks on the PR and who contribute to this library, let's see whether I can get them to help you and -- if necessary -- correct the docs.
Related
I'm new to .NET and to webservice development, so i'm not exactly sure how to implement the requirement i have.
My webservice gets a POST request with some data, which i need to
process to generate a pdf file: name_YYYYMMDDHHmmss.pdf.
For monitoring this i want to have a separate logfile for each request, named like the output file: name_YYYYMMDDHHmmss.log
I would like to avoid passing a config object into every class/function in which i need to add stuff to the log file
I've managed to install Serilog and it works for what i need, but not when i get concurrent requests. I'm also not exactly sure how simultaneous requests are handled in .NET (i have no thread specific code written so far), but as far as i can tell, when i change Global Logger file name, that object is shared across all threads so all of them write to the same file.
I've looked at a bunch of solutions, but i haven't managed to find nothing that suits this, and it seems most people have everything into 1 file...
Is there any clue or tips you can give me? I'm open to using something other than Serilog.
One way to have dynamic file names based on a specific context is by using the Serilog.Sinks.Map and then, via a middleware in the request pipeline, you can add a property to the log context that drives the file name to be used when writing to the log.
Examples of similar usage of Serilog.Sinks.Map to decide which file name to use at run-time:
Serilog - can not log to multiple files based on property
In Serilog dynamically changing log file path?
The best solution that I found to this problem was using Serilog.Sinks.Map. I configured my Logger something like this:
Log.Logger = new LoggerConfiguration()
.WriteTo.Map("Name", "Default", (name, wt) => {
var fileName = name == "Default" ? "log" : $"{log-{name}}"
wt.File($"./{fileName}-.txt");
}).CreateLogger();
Then on my controller, on each method where I needed this feature, I enclosed all the instructions inside a LongContext like this:
[HttpGet]
public IHttpActionResult Get() {
using (LogContext.PushProperty("Name", "theFileName") {
// ...
_myService.Method1();
// ...
}
}
public class MyService : IMyService {
// ...
public void Method1() {
// ...
Log.Information("This is what happened at this point…");
// ...
}
// ...
}
So all the Log's inside will use that context and it will write on a different file with the name you set for that context without having to modify any Log.Information/Error/Warning/etc that you already have on your code.
This is the ugly part... you have to define a context on a root place in order to make those Logs write on a different file. So for a controller method, the first thing you have to do is to enclose all with a LogContext.
After upgrading to Intershop CM 7.10.18.1, we are getting NullPtr exceptions while opening store detail page in backoffice.
ISML template for store details is EditStore_52.isml, which includes ISCountrySelectBox module, which futhermore calls getCountryNamesAndCodes() method.
That method fails with NullPtr exception because of underlined call which returns null.
We are wondering whether this is a bug and whether the intended code was supposed to be:
countriesMap.put(country.getId(), country.getDisplayName(currentLocale));
Please advise on workaround for this situation.
The following is a stack trace for exception.
Intershop delivers address data which can be imported/export through Operations backoffice (e.g. Login at https://localhost:8443/INTERSHOP/web/WFS/SLDSystem using Organization Operations). Out of the box such address data looks like this:
<country>
<id>DE</id>
<custom-attributes>
<custom-attribute dt:dt="string" name="displayName" xml:lang="de-DE">Deutschland</custom-attribute>
<custom-attribute dt:dt="string" name="displayName" xml:lang="fr-FR">Allemagne</custom-attribute>
<custom-attribute dt:dt="string" name="displayName" xml:lang="en-US">Germany</custom-attribute>
</custom-attributes>
</country>
As you can see, it only contains displayName attribute values for de-DE, fr-FR and en-US. A possible workaround in your case would be to export data, include missing attribute values and import it again.
Please note: The work to deliver a fix for this is already in progress. I'm sorry for the inconvenience.
The more convenient way (because editing xml import files is tedious) would be to replace the erroneous implementation using guice module override. In a nutshell:
Copy paste the original implementation of class com.intershop.component.region.internal.geoobject.LocalizedCountryNamesProviderImpl into a class of your own in your custom cartridge. For example: I just created a class AppSFLocalizedCountryNamesProviderImpl in cartridge app_sf_responsive to test this.
Adapt above method according to your needs
Create an override module (See Cookbook - Dependency Injection and ObjectGraphs). Following my example the modules configure operation should look like this:
#Override
protected void configure()
{
bind(LocalizedCountryNamesProvider.class).to(AppSFLocalizedCountryNamesProviderImpl.class);
bindProvider(com.intershop.component.foundation.capi.localization.LocalizedCountryNamesProvider.class)
.to(AppSFLocalizedCountryNamesProviderImpl.class);
}
Publish your cartridge, Restart your server
I'm creating a web app that will allow users to log in to execute certain actions. I followed this tutorial (for simplicity, you can search for "Generate the database to store membership data" for the exact database setup I used).
Everything works fine in development, but when I deploy it and try to register a new user, it gives me the error:
An unhandled exception has occurred: SQLite Error 1: 'no such table: AspNetUsers'.
Is this because I need to do a 'dotnet ef database update' in deployment? If so, is there anyway I can avoid it, such that I can just deploy and have the database setup itself and be ready? The tutorial semi-talked about it by calling 'dbContext.Database.Migrate();', but I have no dbContext in the Configure() method... so I'm not sure how to fill in the gaps.
If there is any information about my code you'd like me to post, I'll be happy to post it for you. Thanks in advance!
I did happen to figure out how to fix the problem, but please bear with me on the details of the solution. It has been so long that I can only remember that Step 1 is definitely necessary, but I'm fairly fuzzy on if we also need to do Step 2. Some point down the line when I have time, I'll revisit this to confirm, but for now, I hope this will give you enough help to overcome the problem.
Step 1: Create your AspNetUsers table in your custom context class that inherits from IdentityDbContext<IdentityUser> with the following code. For the purposes of my example, I'm calling this class: CustomDbContext.
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<IdentityUser>().ToTable("AspNetUsers");
base.OnModelCreating(modelBuilder);
}
Note: If you aren't following the guide or using this for authentication, you'd simply have your custom context class inherit from DbContext.
Step 2: In your Startup.cs, you'll need to put the following code in your Startup() method, where you are literally ensuring that the CustomDbContext database (AspNetUsers) is created and available in production.
using (var client = new CustomDbContext())
{
client.Database.EnsureCreated();
}
Note: There is speculation that you could do client.Database.Migrate() in that using statement instead according to this (credit to Thomas Schneiter for letting me know), but I have not personally tried it to see if it works. There is another SO post relating to this particular piece of code with an answer I posted.
In my SharePoint code, I have the following line:
SPWeb web = site.RootWeb; //site is an SPSite object
When I rebuild my project and run the SPDispose tool on the assembly, I get the following error:
Module: Blah.SharePoint.Features.Core.dll Method:
Blah.SharePoint.Features.Core.Helpers.FeatureDeploymentHelper.RemoveWebPartFiles(Microsoft.SharePoint.SPFeatureReceiverProperties,System.String)
Statement: web := site.{Microsoft.SharePoint.SPSite}get_RootWeb()
Source:
C:\xxx\xxx\Main\Source\SharePoint\Features\Core\Helpers\FeatureDeploymentHelper.cs
Line: 26
Notes: Disposable type not disposed: Microsoft.SharePoint.SPWeb
***This may be a false positive depending on how the type was created or if it is disposed outside the current scope More Information:
http://blogs.msdn.com/rogerla/archive/2008/02/12/sharepoint-2007-and-wss-3-0-dispose-patterns-by-example.aspx#SPDisposeCheckID_140
What I want to do is to have the SPDispose tool ignore this error, so I have pulled the SPDisposeCheckIgnore class and supporting enum into my project, and I've decorated my method appropriately:
[SPDisposeCheckIgnore(SPDisposeCheckID.SPDisposeCheckID_140, "RootWeb does not need disposed.")]
public static void RemoveWebPartFiles(SPFeatureReceiverProperties properties, string assemblyName)
{
...
}
After doing all of this, I still receive the error. Anyone know how I might go about getting rid of that error?
Two things need to be done here.
1) The SPDisposeCheckIgnore class must be defined in the SPDisposeCheck namespace. You CANNOT have your own namespace. See the related comment on this page: http://archive.msdn.microsoft.com/SPDisposeCheck/
2) Anything you are trying to ignore within RunWithElevatedPrivleges must be pulled into an external method or it will not be recognized. This was not being done in the example above, but was being done in other places.
These two rules must be followed for ignore to work. Hope this helps someone else down the road.
Double check how you're retrieving and assigning the RootWeb object. If it's done in an external method, the DisposeChecker might not pick up that it's a RootWeb reference.
I don't see anything wrong with what you've written. I pulled out getting the root web into a static method so I only had to ignore this error in one place, and it works in anonymous delegates. The following worked for me:
public class DisposeUtils
{
[SPDisposeCheckIgnore(SPDisposeCheckID.SPDisposeCheckID_140, "RootWeb does not need disposed. http://blogs.msdn.com/b/rogerla/archive/2009/11/30/sharepoint-2007-2010-do-not-dispose-guidance-spdisposecheck.aspx")]
public static SPWeb GetRootWeb(SPSite site)
{
return site.RootWeb;
}
}
Sorry, I'm not sure if that helps exactly - I'm saying your code should work. Have you checked SPDisposeCheck to see how it handles 'Documented' and 'Undocumented' errors? (I've never been entirely clear what those settings do)
The 'ASP' namespace seems to be a generated because it's not used in the website project's source code, anywhere (or at least not explicitly used by the programmer of the website). I would like to know how it is fully realized.
For example:
Is it the responsibility of MSBuild to drive creation of the ASP namespace and
if so, where is that instruction found? I
know the C# compiler won't create a namespace from nothing of
its own volition, so the ASP namespace must be fed into it,
even if not used by the website programmer. Maybe it's
generated into the source code by a different tool. The
'Temporary ASP.NET Files' folder might have some bearing on it. As you
can see, I want all the gory details in order to unlock and understand
that namespace ...
Visual Studio seems to have tooling that allows the ASP namespace to be used (IntelliSense support for it) but that masks my understanding of it.
How is the 'ASP' namespace realized in a website from start to finish?
(I haven't found a good article that explains all this.)
Here the ASP namespace is shown in .NET Reflector. (This image taken from Rick Strahl's blog)
The ASP. namespace can be used to Load dynamically a custom control with more safe that the cast will works.
You can control what name the custom control can take in the ASP. namespace by placing the ClassName="ControlClass" on the declaration of the name space and the dynamic control now will have a reference to ASP.ControlClass to make a secure cast when you use the LoadControl
You can read the full steps on MSDN http://msdn.microsoft.com/en-us/library/c0az2h86(v=vs.100).aspx
When you do not use the ASP. namespace and left the control takes an automatic name, then the case may fail (I do not know why, but its fail on my sever time to time) The reference that there created are
namespace ASP
{
[CompilerGlobalScope]
public class Control_Class_nameByDirectory : ControlClass
{
[DebuggerNonUserCode]
public ControlClass();
protected override bool SupportAutoEvents { get; }
[DebuggerNonUserCode]
protected override void FrameworkInitialize();
}
}
And when you try to make a cast like (ControlClass)LoadControl("~/module/Control.ascs") it may fail because is recognize it as Control_Class_nameByDirectory and not as ControlClass
Now if you declare the ClassName on the control header as MSD says, the result is the control to get the same ClassName as the one you have define :
namespace ASP
{
[CompilerGlobalScope]
public class ControlClass : global::ControlClass
{
[DebuggerNonUserCode]
public ControlClass();
protected override bool SupportAutoEvents { get; }
[DebuggerNonUserCode]
protected override void FrameworkInitialize();
}
}
and here you can use the ASP.ControlClass to cast the control with out worry if its fail.
So following the steps that described here http://msdn.microsoft.com/en-us/library/c0az2h86(v=vs.100).aspx you can avoid issues like that. (and that I have face them)
The issue of failing to case a custom control with out reference to ASP. namespace have been seen both on Dot net 4.0 and 4.5 versions. And the worst is that is a random failure - meaning that some times is happens, some time not, and I was unable to find the reason.
I'm going to assume that you're looking for the prefix on server control tags... if that's not the case, let me know.
The prefix is registered in the web.config file under configuration/system.Web/pages/controls. You can modify it if you want, or register additional prefixes for your own control libraries.
MSDN info here: http://msdn.microsoft.com/en-us/library/ms164640.aspx
This namespace is used on the code that ASP.NET generates from parsing your .aspx and .ascx files.
I have no idea why you care, though. It's just a namespace. There's nothing "special" about it, and you shouldn't be referencing anything in that namespace.
To understand how all of this works, read "ASP.NET Life Cycle".