Magnetic vector potential of an infinite wire

Using the integral $$A=\frac{\mu_0}{4 \pi} \int \frac{I \vec{dl}}{r}$$ for calculating magnetic vector potential of an infinite wire we get $$A = \left(\frac{\mu_0 I}{4 \pi}\right) \ln(\sec \theta + \tan \theta)$$ which diverges when the limits are from $-\pi$ to $\pi$. We can get around this by solving $B=\nabla \times A$ which gives us a finite answer.

My question is why does the first formula fail for this problem and is it fixable?

Ok, so lets start with the basics, the answer we are expecting is given by: $$\vec B= \frac{\mu_0I}{2\pi r} \hat e_\theta$$ Which is from Ampere's law.
From this we can kind of backwards engineer, to show that: $$\vec A=-\frac{\mu_0I}{2\pi} \ln(r) \hat e_z$$ would work as the potential.
The reason I don't think your method works is because you are forcing the coulomb gauge (i.e. $\nabla \cdot \vec A=0$) onto the system and in this situation the integral diverges. In other words we have the freedom to chose $\vec A$ since: $$\vec A'=\vec A+\nabla(\phi)$$ For some function $\phi$ both satisfy: $$\vec B=\nabla \times \vec A=\nabla \times \vec A'$$ It happens that your choice of $\vec A$ is not well defined in this case, i.e. the coulomb gauge doesn't work.
\begin{align} B &= \nabla \times A \\ \iint B \cdot \mathrm{d}a &= \oint A \cdot \mathrm{d}l \\ \int_a^b \frac{\mu l}{2 \pi r} L \, \mathrm{d}r &= AL \\ A &= \frac{\mu l}{2 \pi} \ln{\frac{b}{a}} Z \end{align}
• Welcome to SE.Physics! I converted the equations in your picture to $\mathrm{\TeX}$ (which is implemented through MathJax here), as @Chair recommended. If you try to edit your post, you can see the $\mathrm{\TeX}$ code to pick up on how it's done and make any changes that might improve the answer. In general, you can write $x$ to render $x$. – Nat Jun 5 '18 at 14:22